public static void AddBuildingBlocks(this IServiceCollection services, params Assembly[] autoMapperAssemblies)
        {
            services.AddTransient(typeof(IPipelineBehavior <,>), typeof(ValidatorBehavior <,>));
            services.AddTransient(typeof(IPipelineBehavior <,>), typeof(LoggingBehavior <,>));

            services.TryAddTransient <IDomainMediator, MediatRAdapter>();

            services.AddTransient <IEntityValidatorFactory, DataAnnotationsEntityValidatorFactory>();

            services.AddAutoMapper(autoMapperAssemblies);

            //sigletons
            TypeAdapterLocator.SetCurrent(new AutoMapperTypeAdapterFactory(autoMapperAssemblies));
            EntityValidatorLocator.SetCurrent(new DataAnnotationsEntityValidatorFactory());
        }
예제 #2
0
        // 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());
        }
예제 #3
0
 private static void RegisterSingletons()
 {
     TypeAdapterLocator.SetCurrent(new AutoMapperTypeAdapterFactory());
     EntityValidatorLocator.SetCurrent(new DataAnnotationsEntityValidatorFactory());
     LoggerLocator.SetCurrent(new Log4NetLoggerFactory());
 }