// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { var container = new Lamar.Container(x => { services.AddScoped <IMessagingService, StructureMappingService>(); services.AddControllersWithViews(); services.AddMvc() .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining <LoginValidatorHandler>()) .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining <RegisterValidationHandler>()) .AddFluentValidation(fv => fv.RegisterValidatorsFromAssemblyContaining <ChangePasswordValidator>()); services.AddDbContext <AppContext>(options => options.UseSqlServer(Configuration.GetConnectionString("DevConnection"), b => b.MigrationsAssembly("MVCCore"))); services.AddDistributedMemoryCache(); services.AddSession(); services.AddMediatR(typeof(Startup)); services.AddMediatR(Assembly.GetExecutingAssembly()); services.AddIdentity <IdentityUser, IdentityRole>() .AddEntityFrameworkStores <AppContext>(); services.Configure <PasswordHasherOptions>(options => options.CompatibilityMode = PasswordHasherCompatibilityMode.IdentityV3); services.ConfigureApplicationCookie(options => options.LoginPath = "/login"); }); }
private static IMediator BuildMediator(WrappingWriter writer) { var container = new Lamar.Container(cfg => { cfg.Scan(scanner => { scanner.AssemblyContainingType <Ping>(); scanner.ConnectImplementationsToTypesClosing(typeof(ICommandHandler <,>)); scanner.ConnectImplementationsToTypesClosing(typeof(IQueryHandler <,>)); }); //Pipeline cfg.For(typeof(IPipelineBehavior <,>)).Add(typeof(PreProcessorBehavior <,>)); cfg.For(typeof(IPipelineBehavior <,>)).Add(typeof(PostProcessorBehavior <,>)); // This is the default but let's be explicit. At most we should be container scoped. cfg.For <IMediator>().Use <Mediator>().Transient(); cfg.For <eQuantic.Core.Ioc.IContainer>().Use(ctx => new Container(ctx)); cfg.For <TextWriter>().Use(writer); }); var mediator = container.GetInstance <IMediator>(); return(mediator); }