Giter Site home page Giter Site logo

hungud / mediatr.extensions.microsoft.dependencyinjection Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jbogard/mediatr.extensions.microsoft.dependencyinjection

0.0 1.0 0.0 134 KB

MediatR extensions for Microsoft.Extensions.DependencyInjection

License: MIT License

PowerShell 2.44% C# 97.56%

mediatr.extensions.microsoft.dependencyinjection's Introduction

MediatR extensions for Microsoft.Extensions.DependencyInjection

CI NuGet NuGet MyGet (dev)

Scans assemblies and adds handlers, preprocessors, and postprocessors implementations to the container. To use, with an IServiceCollection instance:

services.AddMediatR(typeof(MyHandler));

or with an assembly:

services.AddMediatR(typeof(Startup).GetTypeInfo().Assembly);

This registers:

  • IMediator as transient
  • IRequestHandler<> concrete implementations as transient
  • INotificationHandler<> concrete implementations as transient
  • IRequestPreProcessor<> concrete implementations as transient
  • IRequestPostProcessor<,> concrete implementations as transient
  • IRequestExceptionHandler<,,> concrete implementations as transient
  • IRequestExceptionAction<,>) concrete implementations as transient

This also registers open generic implementations for:

  • INotificationHandler<>
  • IRequestPreProcessor<>
  • IRequestPostProcessor<,>
  • IRequestExceptionHandler<,,>
  • IRequestExceptionAction<,>

Keep in mind that the built-in container does not support constrained open generics. If you want this behavior, you will need to add any one of the conforming containers.

To customize registration, such as lifecycle or the registration type:

services.AddMediatR(cfg => cfg.Using<MyCustomMediator>().AsSingleton(), typeof(Startup));

To register behaviors, register them individually before or after calling AddMediatR.

Open generics

If you have an open generic not listed above, you'll need to register it explicitly. For example, if you have an open generic request handler, register the open generic types explicitly:

services.AddTransient(typeof(IRequestHandler<,>), typeof(GenericHandlerBase<,>));

This won't work with generic constraints, so you're better off creating an abstract base class and concrete closed generic classes that fill in the right types.

mediatr.extensions.microsoft.dependencyinjection's People

Contributors

ardalis avatar dpaquette avatar ewoutdboer avatar ffje avatar henkmollema avatar jamesrandall avatar jbogard avatar ljani avatar remcoros avatar steventcramer avatar vasilisgaitanidis avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.