Created
December 17, 2015 21:49
-
-
Save AlonAm/95a90b47c63a8b311c0f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MediatorPipelineModule : Autofac.Module | |
{ | |
protected override void Load(ContainerBuilder builder) | |
{ | |
RegisterPipeline(builder); | |
RegisterAsyncPreRequestHandlers(builder); | |
RegisterAsyncPostRequestHandlers(builder); | |
RegisterPreRequestHandlers(builder); | |
RegisterPostRequestHandlers(builder); | |
} | |
private static void RegisterPipeline(ContainerBuilder builder) | |
{ | |
builder.RegisterGenericDecorator(typeof (AsyncMediatorPipeline<,>), typeof (IAsyncRequestHandler<,>), | |
"async-handler") | |
.InstancePerLifetimeScope(); | |
builder.RegisterGenericDecorator(typeof (MediatorPipeline<,>), typeof (IRequestHandler<,>), "handler") | |
.InstancePerLifetimeScope(); | |
} | |
private static void RegisterPostRequestHandlers(ContainerBuilder builder) | |
{ | |
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()) | |
.As(type => type.GetInterfaces() | |
.Where(interfacetype => interfacetype.IsClosedTypeOf(typeof(IPostRequestHandler<,>)))) | |
.InstancePerLifetimeScope(); | |
} | |
private static void RegisterAsyncPostRequestHandlers(ContainerBuilder builder) | |
{ | |
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()) | |
.As(type => type.GetInterfaces() | |
.Where(interfacetype => interfacetype.IsClosedTypeOf(typeof(IAsyncPostRequestHandler<,>)))) | |
.InstancePerLifetimeScope(); | |
} | |
private static void RegisterPreRequestHandlers(ContainerBuilder builder) | |
{ | |
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()) | |
.As(type => type.GetInterfaces() | |
.Where(interfacetype => interfacetype.IsClosedTypeOf(typeof(IPreRequestHandler<>)))) | |
.InstancePerLifetimeScope(); | |
} | |
private static void RegisterAsyncPreRequestHandlers(ContainerBuilder builder) | |
{ | |
builder.RegisterAssemblyTypes(Assembly.GetExecutingAssembly()) | |
.As(type => type.GetInterfaces() | |
.Where(interfacetype => interfacetype.IsClosedTypeOf(typeof(IAsyncPreRequestHandler<>)))) | |
.InstancePerLifetimeScope(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment