Last active
June 14, 2022 08:50
-
-
Save anderly/53e3b98c440479a9171643a79d2720d7 to your computer and use it in GitHub Desktop.
MediatR Pipeline Behavior Registration.
This file contains 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
// Register MediatR Pipeline Behaviors | |
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(LoggingBehavior<,>)); | |
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehavior<,>)); | |
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(CachingBehavior<,>)); | |
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(FallbackBehavior<,>)); | |
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(RetryBehavior<,>)); | |
// ICachePolicy discovery and registration | |
services.Scan(scan => scan | |
.FromAssemblies(assembly) | |
.AddClasses(classes => classes.AssignableTo(typeof(ICachePolicy<,>))) | |
.AsImplementedInterfaces() | |
.WithTransientLifetime()); | |
// IFallbackHandler discovery and registration | |
services.Scan(scan => scan | |
.FromAssemblies(typeof(Startup).Assembly) | |
.AddClasses(classes => classes.AssignableTo(typeof(IFallbackHandler<,>))) | |
.UsingRegistrationStrategy(RegistrationStrategy.Skip) | |
.AsImplementedInterfaces() | |
.WithTransientLifetime()); | |
// IFallbackHandler discovery and registration | |
services.Scan(scan => scan | |
.FromAssemblies(typeof(Startup).Assembly) | |
.AddClasses(classes => classes.AssignableTo(typeof(IRetryableRequest<,>))) | |
.UsingRegistrationStrategy(RegistrationStrategy.Skip) | |
.AsImplementedInterfaces() | |
.WithTransientLifetime()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment