/// <summary>
        /// projected a enumerable collection of items
        /// </summary>
        /// <typeparam name="TProjection">The dtop projection type</typeparam>
        /// <param name="items">the collection of entity items</param>
        /// <returns>Projected collection</returns>
        public static List <TProjection> ProjectedAsCollection <TProjection>(this IEnumerable <object> items)
            where TProjection : class
        {
            var adapter = TypeAdapterLocator.CreateAdapter();

            return(adapter.Adapt <List <TProjection> >(items));
        }
        /// <summary>
        /// Project a type using a DTO
        /// </summary>
        /// <typeparam name="TProjection">The dto projection</typeparam>
        /// <param name="item">The source entity to project</param>
        /// <returns>The projected type</returns>
        public static TProjection ProjectedAs <TProjection>(this object item)
            where TProjection : class
        {
            var adapter = TypeAdapterLocator.CreateAdapter();

            return(adapter.Adapt <TProjection>(item));
        }
        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());
        }
Beispiel #4
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());
        }
Beispiel #5
0
 private static void RegisterSingletons()
 {
     TypeAdapterLocator.SetCurrent(new AutoMapperTypeAdapterFactory());
     EntityValidatorLocator.SetCurrent(new DataAnnotationsEntityValidatorFactory());
     LoggerLocator.SetCurrent(new Log4NetLoggerFactory());
 }