Last active
April 3, 2018 23:02
-
-
Save wellingtonjhn/df75023e50bf4d3f1b6c5122a5bba3b4 to your computer and use it in GitHub Desktop.
ASP.Net Startup MediatR DI
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 Startup | |
| { | |
| // ... restante do arquivo | |
| public void ConfigureServices(IServiceCollection services) | |
| { | |
| AddApplicationServices(services); | |
| services.AddMvc(); | |
| } | |
| private static void AddApplicationServices(IServiceCollection services) | |
| { | |
| services.AddScoped<IUserRepository, UserRepository>(); | |
| AddMediatr(services); | |
| } | |
| private static void AddMediatr(IServiceCollection services) | |
| { | |
| const string applicationAssemblyName = "DemoMediatR.Application"; | |
| var assembly = AppDomain.CurrentDomain.Load(applicationAssemblyName); | |
| AssemblyScanner | |
| .FindValidatorsInAssembly(assembly) | |
| .ForEach(result => services.AddScoped(result.InterfaceType, result.ValidatorType)); | |
| services.AddScoped(typeof(IPipelineBehavior<,>), typeof(FailFastRequestBehavior<,>)); | |
| services.AddMediatR(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment