Example #1
0
        public static IServiceCollection AddRepositories(
            this IServiceCollection services,
            string dbConnectionString,
            string rootPath)
        {
            var mapperConfiguration = new MapperConfiguration(cfg => cfg.AddProfile <MappingProfile>());

            mapperConfiguration.CompileMappings();

            return(services
                   .AddDbContext(dbConnectionString, rootPath)

                   .AddTransient <IAssetRepository, AssetRepository>()
                   .AddTransient <ITrackingDeviceRepository, TrackingDeviceRepository>()
                   .AddTransient <ITrackingPointRepository, TrackingPointRepository>()
                   .AddTransient <IConfigurationRepository, ConfigurationRepository>()
                   .AddTransient <ILocationRepository, LocationRepository>()
                   .AddTransient <IUserRepository, UserRepository>()
                   .AddTransient <IRoleRepository, RoleRepository>()
                   .AddTransient <ITripRepository, TripRepository>()
                   .AddTransient <IGeoFenceRepository, GeoFenceRepository>()
                   .AddTransient <IGeoFenceUpdateRepository, GeoFenceUpdateRepository>()
                   .AddTransient <IAssetPropertiesRepository, AssetPropertiesRepository>()
                   .AddTransient <IInstrumentationRepository, InstrumentationRepository>()
                   .AddTransient <ITokenRepository, TokenRepository>()

                   .AddSingleton(mapperConfiguration)

                   .AddScoped <TrackingDeviceAssetResolver>()
                   .AddScoped <TokenTrackingDeviceResolver>()
                   .AddScoped <TokenUserResolver>()

                   .AddScoped <IMapper>(ctx => new Mapper(ctx.GetService <MapperConfiguration>(), t => ctx.GetService(t))));
        }
        public AutoMapperTypeAdapterFactory(bool assertConfigurationIsValid, bool compileMappings)
        {
            var profiles = GetAssemblies()
                           .SelectMany(p => p.GetTypes())
                           .Where(p => p.GetTypeInfo().BaseType == typeof(Profile));

            var configuration = new MapperConfiguration(cfg => {
                cfg.AllowNullCollections       = true;
                cfg.AllowNullDestinationValues = true;
                foreach (var profile in profiles)
                {
                    cfg.AddProfile(Activator.CreateInstance(profile) as Profile);
                }
            });


            if (assertConfigurationIsValid)
            {
                configuration.AssertConfigurationIsValid();
            }
            if (compileMappings)
            {
                configuration.CompileMappings();
            }

            _mapper = configuration.CreateMapper();
        }
Example #3
0
        public BookingServiceTests()
        {
            MapperConfiguration mappingConfig = new MapperConfiguration(config =>
            {
                config.CreateMap <Flight, FlightEntity>();
                config.CreateMap <FlightEntity, Flight>();
                config.CreateMap <FlightSeatTypeCost, FlightSeatTypeCostEntity>();
                config.CreateMap <FlightSeatTypeCostEntity, FlightSeatTypeCost>();
                config.CreateMap <FlightFilter, FlightFilterEntity>();
                config.CreateMap <FlightFilterEntity, FlightFilter>();
                config.CreateMap <FlightBookInfo, FlightBookInfoEntity>();
                config.CreateMap <FlightBookInfoEntity, FlightBookInfo>();
                config.CreateMap <SeatBook, SeatBookEntity>();
                config.CreateMap <SeatBookEntity, SeatBook>();
            });

            mappingConfig.CompileMappings();

            IMapper mapper = mappingConfig.CreateMapper();

            IBookingSettings bookingSettings = new BookingSettingsMock(new TimeSpan(0, 5, 0));

            _bookingService = new BookingService(
                mapper,
                new FlightRepositoryMock(bookingSettings),
                new AirplanesRepositoryMock(),
                new UserInfoMock(1)
                );
        }
Example #4
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddGrpc();

            services.AddAutoMapper(typeof(Startup));

            var configuration = new MapperConfiguration(cfg => {
                cfg.SourceMemberNamingConvention      = new LowerUnderscoreNamingConvention();
                cfg.DestinationMemberNamingConvention = new PascalCaseNamingConvention();
            });

            configuration.CompileMappings();

            services.AddDbContext <ProducerDbContext>();
            services.AddScoped <IPaymentRepository, PaymentRepository>();
            services.AddScoped <IUserRepository, UserRepository>();
            services.AddScoped <ProcessPaymentService>();

            var producerConfig = new ProducerConfig();

            Configuration.Bind("ProducerConfig", producerConfig);
            services.AddSingleton(producerConfig);

            var consumerConfig = new ConsumerConfig();

            Configuration.Bind("ConsumerConfig", consumerConfig);
            consumerConfig.AutoOffsetReset = AutoOffsetReset.Earliest;
            services.AddSingleton(consumerConfig);

            services.AddSingleton <IHostedService, ProcessPaymentService.ProcessPayment>();
            services.AddSingleton <IHostedService, ProcessPaymentService.ProcessPaymentFailed>();
        }
Example #5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public virtual void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();

            services.Configure <CovidDatabaseSettings>(Configuration.GetSection(nameof(CovidDatabaseSettings)));
            services.Configure <ImportOptions>(options => Configuration.GetSection("ImportOptions").Bind(options));

            services.AddSingleton <ICovidDatabaseSettings>(sp => sp.GetRequiredService <IOptions <CovidDatabaseSettings> >().Value)
            .AddScoped <IUnitOfWork, UnitOfWork>()
            .AddScoped <ICovidImportService, QuestionaireImportService>()
            .AddScoped <IImportStatisticsService, ImportStatisticsService>()
            .AddHostedService <ImportService>();

            var mappingConfig = new MapperConfiguration(conf =>
            {
                conf.AddProfile(new EntityToDtoProfiles());
                conf.AddProfile(new DtoToEntityProfiles());
            });

            mappingConfig.AssertConfigurationIsValid();
            mappingConfig.CompileMappings();

            var mapper = mappingConfig.CreateMapper();

            services.AddSingleton(mapper);
        }
Example #6
0
        public void ConfigureServices(IServiceCollection services)
        {
            string connection = _configuration.GetConnectionString("DefaultConnection");

            services.AddDbContextPool <ApplicationDbContext>(options =>
                                                             options.UseSqlServer(connection)
                                                             );

            services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie(options =>     //CookieAuthenticationOptions
            {
                options.LoginPath = new Microsoft.AspNetCore.Http.PathString("/log-in");
            });

            services.AddMvc(options => options.EnableEndpointRouting = false);

            services.AddScoped <IUserRepository, UserRepository>();
            services.AddScoped <IProductRepository, ProductRepository>();
            services.AddScoped <ICartRepository, CartRepository>();
            services.AddScoped <IOrderRepository, OrderRepository>();

            var mapperCOnfiguration = new MapperConfiguration(cfg => cfg.AddProfile <StoreModelProfile>());

            mapperCOnfiguration.CompileMappings();



            services.AddSingleton(mapperCOnfiguration);
            services.AddSingleton(mapperCOnfiguration.CreateMapper());
        }
Example #7
0
        public static IMapper SetupMappers()
        {
            MapperConfiguration config = new MapperConfiguration(cfg => {
                // ZDataModel <-> ZDTOModel
                // Activity
                cfg.AddProfile <ActivityDataAutoMapper>();
                // Audit Trail
                cfg.AddProfile <AuditTrailDataAutoMapper>();
                // Identity
                cfg.AddProfile <IdentityDataAutoMapper>();
                // Application
                cfg.AddProfile <NorthwindDataAutoMapper>(); // !!!

                // ZViewModel <-> ZDTOModel
                // Activity
                cfg.AddProfile <ActivityViewAutoMapper>();
                // Audit Trail
                cfg.AddProfile <AuditTrailViewAutoMapper>();
                // Identity
                cfg.AddProfile <IdentityViewAutoMapper>();
                // Application
                cfg.AddProfile <NorthwindViewAutoMapper>(); // !!!
            });

            config.CompileMappings();
            config.AssertConfigurationIsValid();

            return(config.CreateMapper());
        }
Example #8
0
        public static IMapper GetMapper(Action <IMapperConfigurationExpression> configure = null)
        {
            var hashCode = configure?.Method.GetHashCode() ?? 0;

            if (IsCacheEnabled && serviceProvidersAuto.ContainsKey(hashCode))
            {
                return(serviceProvidersAuto[hashCode]);
            }

            var config = new MapperConfiguration(conf =>
            {
                conf.CreateMap <Enum, EnumVm>()
                .ForMember(x => x.Id, c => c.MapFrom(y => y.GetValue()))
                .ForMember(x => x.Name, c => c.MapFrom(y => y.GetDisplayName()));
                conf.CreateMap <Enum, string>().ConstructUsing(c => c.GetDisplayName());

                CommonConfiguration?.Invoke(conf);
                configure?.Invoke(conf);
            });

            config.CompileMappings();
            var mapper = config.CreateMapper();

            return(IsCacheEnabled ? serviceProvidersAuto.AddOrUpdate(hashCode, mapper, (i, m) => m) : mapper);
        }
Example #9
0
        public static IMapper GetConfiguredMapper()
        {
            var mapperConfiguration = new MapperConfiguration(RegisterMappings);

            mapperConfiguration.CompileMappings();
            return(mapperConfiguration.CreateMapper());
        }
        public FlightServiceTests()
        {
            MapperConfiguration mappingConfig = new MapperConfiguration(config =>
            {
                config.CreateMap <Flight, FlightEntity>();
                config.CreateMap <FlightEntity, Flight>();
                config.CreateMap <FlightSeatTypeCost, FlightSeatTypeCostEntity>();
                config.CreateMap <FlightSeatTypeCostEntity, FlightSeatTypeCost>();
                config.CreateMap <FlightFilter, FlightFilterEntity>();
                config.CreateMap <FlightFilterEntity, FlightFilter>();
                config.CreateMap <FlightBookInfo, FlightBookInfoEntity>();
                config.CreateMap <FlightBookInfoEntity, FlightBookInfo>();
            });

            mappingConfig.CompileMappings();

            IMapper mapper = mappingConfig.CreateMapper();

            IBookingSettings bookingSettings = new BookingSettingsMock(TimeSpan.FromMinutes(5));

            _flightService = new FlightService(
                mapper,
                new FlightRepositoryMock(bookingSettings),
                new AirportRepositoryMock(),
                new AirplanesRepositoryMock()
                );
        }
Example #11
0
        private IMapper GetMapper()
        {
            var mapperConfiguration = new MapperConfiguration(RegisterMappers);

            mapperConfiguration.CompileMappings();
            return(mapperConfiguration.CreateMapper());
        }
        public MapperTests()
        {
            var mapperConfiguration = new MapperConfiguration(cfg => { cfg.AddProfile <DemoServerProfile>(); });

            mapperConfiguration.AssertConfigurationIsValid();
            mapperConfiguration.CompileMappings();
            _mapper = mapperConfiguration.CreateMapper();
        }
Example #13
0
 public AutoMapperConfiguration()
 {
     _mapperConfiguration = new MapperConfiguration(c =>
     {
         c.ApplyConfiguration(this.GetType().Assembly);
     });
     _mapperConfiguration.CompileMappings();
 }
        public GeocodingRegistry()
        {
            var mapperConfiguration = new MapperConfiguration(cfg => { cfg.AddProfile(new GeocodingMappingProfile()); });

            mapperConfiguration.CompileMappings();

            For <IGeocodingService>().Use <GeocodingService>().Ctor <IMapper>().Is(mapperConfiguration.CreateMapper());
        }
Example #15
0
        public static void Configure()
        {
            MapperConfiguration config = new MapperConfiguration(cfg => RegisterProfiles(cfg));

            config.AssertConfigurationIsValid();
            config.CompileMappings();

            ModelMapper.Initialize(config.CreateMapper());
        }
Example #16
0
        public void OneTimeSetup()
        {
            var mapperConfiguration = new MapperConfiguration(cfg =>
                                                              cfg.AddProfiles(new[] { new StudentProfile() }));

            mapperConfiguration.CompileMappings();
            mapperConfiguration.AssertConfigurationIsValid();
            mapper = mapperConfiguration.CreateMapper();
        }
Example #17
0
        private IMapper CreateMapper()
        {
            var map = new MapperConfiguration(Create);

            map.AssertConfigurationIsValid();
            map.CompileMappings();

            return(map.CreateMapper());
        }
Example #18
0
        public ShowMappingProfileTests()
        {
            _config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <ShowMappingProfile>();
            });

            _config.CompileMappings();
        }
        public DeliveryRegistry()
        {
            var mapperConfiguration = new MapperConfiguration(cfg => { cfg.AddProfile(new DeliveryMappingProfile()); });

            mapperConfiguration.CompileMappings();

            For <IDeliveryService>().Use <DeliveryService>().Ctor <IMapper>().Is(mapperConfiguration.CreateMapper());
            For <ICacheHelper>().Use <CacheHelper>();
        }
Example #20
0
        public void AutoMapperConfigurationTest()
        {
            var mapperConfiguration = new MapperConfiguration(cfg =>
            {
                cfg.AddMaps(Collector.LoadAssemblies("Sandbox"));
            });

            mapperConfiguration.CompileMappings();
            mapperConfiguration.AssertConfigurationIsValid();
        }
Example #21
0
        public static void RegisterMappings()
        {
            var config = new MapperConfiguration(cfg =>
                                                 cfg.AddMaps(
                                                     Assembly.GetExecutingAssembly()
                                                     )
                                                 );

            config.CompileMappings();
        }
Example #22
0
        public void ConfigurationTest()
        {
            var mapperConfiguration = new MapperConfiguration(cfg =>
            {
                cfg.AddMaps(typeof(AutoMapperCreator).GetTypeInfo().Assembly);
            });

            mapperConfiguration.CompileMappings();
            mapperConfiguration.AssertConfigurationIsValid();
        }
        public InvoiceGatewayRegistry()
        {
            var mapperConfiguration = new MapperConfiguration(cfg => { cfg.AddProfile(new InvoiceGatewayMappingProfile()); });

            mapperConfiguration.CompileMappings();

            ForConcreteType <InvoiceGatewayService>().Configure.Ctor <IMapper>().Is(mapperConfiguration.CreateMapper());
            Forward <InvoiceGatewayService, IInvoiceGatewayService>();
            Forward <InvoiceGatewayService, ICustomerLookupService>();
        }
        public static void Configure()
        {
            var configuration = new MapperConfiguration(cfg =>
            {
                cfg.CreateMap <Movie, MovieViewModel>();
                cfg.CreateMap <Genre, GenreViewModel>();
                cfg.CreateMap <GenreMovie, GenreMovieViewModel>();
            });

            configuration.CompileMappings();
        }
Example #25
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            //basic auth config
            services
            .AddAuthentication(BasicAuthenticationDefaults.AuthenticationScheme)
            .AddBasicAuthentication(
                options =>
            {
                options.Realm  = "RestTest";
                options.Events = new BasicAuthenticationEvents
                {
                    OnValidatePrincipal = context =>
                    {
                        if ((context.UserName == "user") && (context.Password == "password"))
                        {
                            var claims = new List <Claim>
                            {
                                new Claim(ClaimTypes.Name, context.UserName, context.Options.ClaimsIssuer)
                            };

                            var principal     = new ClaimsPrincipal(new ClaimsIdentity(claims, context.Scheme.Name));
                            context.Principal = principal;
                        }
                        else
                        {
                            context.AuthenticationFailMessage = "Authentication failed.";
                        }

                        return(Task.CompletedTask);
                    }
                };
            });


            //mapper config
            var mapperConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new Api.Models.Mapping.RequestsProfile());
                mc.AddProfile(new Infrastructure.Data.Mapping.DataProfiles());
            });

            mapperConfig.CompileMappings();
            services.AddSingleton(mapperConfig.CreateMapper());

            //swagger config
            services.AddSwaggerGen(c =>
            {
                c.SwaggerDoc("v1", new OpenApiInfo {
                    Title = "RestTestApi"
                });
            });

            services.AddControllers();
        }
Example #26
0
        public UsersControllerTests()
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddProfile <MapperProfile>();
            });

            config.AssertConfigurationIsValid();
            config.CompileMappings();
            _mapper = config.CreateMapper();
        }
        public AutoMapperSetup()
        {
            var config = new MapperConfiguration(cfg =>
            {
                cfg.AddMaps(typeof(UserProfile).Assembly);
            });

            config.CompileMappings();

            Mapper = config.CreateMapper();
        }
        protected IMapper CreateMapper(Action <IMapperConfigurationExpression> cfg)
        {
            var map = new MapperConfiguration(cfg);

            map.CompileMappings();

            var mapper = map.CreateMapper();

            mapper.ConfigurationProvider.AssertConfigurationIsValid();
            return(mapper);
        }
Example #29
0
        static AutoMapperConfig()
        {
            var config = new MapperConfiguration(cfg =>
            {
                CompanyMapping(cfg);
                InvoiceMapping(cfg);
            });

            config.CompileMappings();
            _mapper = config.CreateMapper();
        }
Example #30
0
        /// <summary>
        /// Initialization method
        /// </summary>
        public IMapper InitializeAutoMapper()
        {
            var c = new MapperConfigurationExpression();

            c.AddMaps(Assembly.GetExecutingAssembly());
            Mapper.Initialize(c);
            var mapperConfig = new MapperConfiguration(c);

            mapperConfig.CompileMappings();
            return(new Mapper(mapperConfig));
        }