Skip to content

ScarletKuro/MediatR.SimpleInjector.FlowingScope

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MediatR.SimpleInjector.FlowingScope

Nuget Nuget GitHub

Adds support to use MediatR with SimpleInjector's ScopedLifestyle.Flowing.

📜Samples

  1. MediatRSimpleInjectorLab - Minimal getting started project.

🚀Getting Started

Register MediatR

You need register everything by yourself. There is no helper class for that, because some configuration is up to the user. Example:

var assemblies = AppDomain.CurrentDomain.GetAssemblies();

var container = new Container();
container.Options.DefaultScopedLifestyle = ScopedLifestyle.Flowing;
container.Register<IMediator, MediatRScoped>(Lifestyle.Scoped);
container.Register<ISender, MediatRScoped>(Lifestyle.Scoped);
container.Register<IPublisher, MediatRScoped>(Lifestyle.Scoped);

container.Register(typeof(IRequestHandler<,>), assemblies);

container.RegisterHandlers(typeof(INotificationHandler<>), assemblies);
container.RegisterHandlers(typeof(IRequestExceptionAction<,>), assemblies);
container.RegisterHandlers(typeof(IRequestExceptionHandler<,,>), assemblies);
container.RegisterHandlers(typeof(IStreamRequestHandler<,>), assemblies);

//Pipeline
container.Collection.Register(typeof(IPipelineBehavior<,>), new[]
{
	typeof(RequestExceptionProcessorBehaviorScoped<,>),
	typeof(RequestExceptionActionProcessorBehaviorScoped<,>),
	typeof(RequestPreProcessorBehavior<,>),
	typeof(RequestPostProcessorBehavior<,>),
}, Lifestyle.Scoped);
container.Collection.Register(typeof(IRequestPreProcessor<>), new[] { typeof(EmptyRequestPreProcessor<>) });
container.Collection.Register(typeof(IRequestPostProcessor<,>), new[] { typeof(EmptyRequestPostProcessor<,>) });

Resolving Scope

using Scope scope = new Scope(container);
// You will have to resolve directly from the scope.
var instance = scope.GetInstance<ScopedInstance>();

For more details refer to SimpleInjector documentation

About

Adds support to use MediatR with SimpleInjector's ScopedLifestyle.Flowing.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages