Skip to content

Instantly share code, notes, and snippets.

@wellingtonjhn
Last active April 3, 2018 23:02
Show Gist options
  • Select an option

  • Save wellingtonjhn/df75023e50bf4d3f1b6c5122a5bba3b4 to your computer and use it in GitHub Desktop.

Select an option

Save wellingtonjhn/df75023e50bf4d3f1b6c5122a5bba3b4 to your computer and use it in GitHub Desktop.
ASP.Net Startup MediatR DI
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