// This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.TryAddTransient <IHttpContextAccessor, HttpContextAccessor>(); services.AddCors(); services.AddSecurity(Configuration); services.AddDbContext <CarRentalUnitOfWork>(optionsBuilder => { optionsBuilder .UseMySQL(Configuration.GetConnectionString("CarRentalDataSource")); }, ServiceLifetime.Scoped); // registers repositories services.AddTransient <ReadModel.IAvailableCarRepository, Infrastructure.Repositories.AvailableCarRepository>(); services.AddTransient <IAvailableCarRepository, AvailableCarRepository>(); services.AddTransient <IUserRepository, UserRepository>(); services.AddTransient <IBookingRepository, BookingRepository>(); //register application services services.AddTransient <IAvailableCarAppService, AvailableCarAppService>(); services.AddTransient <IAvailableCarService, AvailableCarService>(); services.AddMediatR(typeof(CreateBookingCommand).Assembly); services.AddAutoMapper(); services.AddMvc() .AddFluentValidation(fv => { fv.ImplicitlyValidateChildProperties = true; fv.RegisterValidatorsFromAssemblyContaining <AddressModel>(); fv.RegisterValidatorsFromAssemblyContaining <CreateBookingCommand>(); }); //sigletos TypeAdapterLocator.SetCurrent(new AutoMapperTypeAdapterFactory()); EntityValidatorLocator.SetCurrent(new DataAnnotationsEntityValidatorFactory()); LoggerLocator.SetCurrent(new Log4NetLoggerFactory()); }
private static void RegisterSingletons() { TypeAdapterLocator.SetCurrent(new AutoMapperTypeAdapterFactory()); EntityValidatorLocator.SetCurrent(new DataAnnotationsEntityValidatorFactory()); LoggerLocator.SetCurrent(new Log4NetLoggerFactory()); }