Exemplo n.º 1
0
        /// <summary>
        ///     Used to setup AutoMapper
        /// </summary>
        /// <param name="additionalProfiles">These profiles will override any existing mappings in an additive manner. Base and ProjectTo are applied automatically.</param>
        /// <exception cref="AutoMapperConfigurationException">Thrown the mapping configuration is invalid - check the logs</exception>
        public static void InitializeMappers(params Profile[] additionalProfiles)
        {
            if (!hasInitialized)
            {
                hasInitialized = true;
            }
            else
            {
                throw new AutoMapperConfigurationException("InitializeMappers should only be called once during the lifetime of an application.");
            }

            // Setup Mapper
            Mapper.AddProfile(Api);

            if (additionalProfiles != null)
            {
                foreach (Profile additionalProfile in additionalProfiles)
                {
                    Mapper.AddProfile(additionalProfile);
                }
            }

            // Verify Mapper configuration
            Mapper.AssertConfigurationIsValid();

            // Setup ProjectToMapper
            ConfigurationStore getAllConfig = CreateConfiguration();

            ApiProjectToMapper = CreateMapper(getAllConfig);

            getAllConfig.AddProfile(Api);
            getAllConfig.AddProfile(ApiProjectTo);
        }
        public static IMappingEngine CreateEngine(Profile mappingProfile)
        {
            ConfigurationStore store = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.Mappers);
            store.AssertConfigurationIsValid();
            MappingEngine engine = new MappingEngine(store);

            store.AddProfile(mappingProfile);
            return engine;
        }
Exemplo n.º 3
0
        public static IMappingEngine CreateEngine(Profile mappingProfile)
        {
            ConfigurationStore store = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.Mappers);

            store.AssertConfigurationIsValid();
            MappingEngine engine = new MappingEngine(store);

            store.AddProfile(mappingProfile);
            return(engine);
        }
Exemplo n.º 4
0
        private IMappingEngine CustomMappingEngine()
        {
            ConfigurationStore store  = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.Mappers);
            MappingEngine      engine = new MappingEngine(store);

            store.AddProfile(new OrderToOrderMapperProfile002(engine));
            store.AllowNullDestinationValues = true;
            store.AssertConfigurationIsValid();
            return(engine);
        }
    public MapperFactory(IEnumerable <Profile> profiles)
    {
        var platformSpecificRegistry = AutoMapper.Internal.PlatformAdapter.Resolve <IPlatformSpecificMapperRegistry>();

        platformSpecificRegistry.Initialize();
        _config = new AutoMapper.ConfigurationStore(new TypeMapFactory(), AutoMapper.Mappers.MapperRegistry.Mappers);
        foreach (var profile in profiles)
        {
            _config.AddProfile(profile);
        }
    }
Exemplo n.º 6
0
        public static MappingEngine Configure(IWindsorContainer container)
        {
            var configurationStore = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.Mappers);

            configurationStore.ConstructServicesUsing(container.Resolve);
            var engine = new MappingEngine(configurationStore);

            configurationStore.AddProfile(new GenericDtoToCollectionJsonMappingProfile <BeerDto>(engine));


            return(engine);
        }
Exemplo n.º 7
0
        static TestContext()
        {
            var config = new ConfigurationStore(new TypeMapFactory(), MapperRegistry.AllMappers());

            Mapper = new MappingEngine(config);

            var mappings = GetMappingProfileTypes <CoreMarker>();

            mappings = mappings.Union(GetMappingProfileTypes <MappingAutoMapperMarker>());

            foreach (var mapping in mappings)
            {
                config.AddProfile((Profile)Activator.CreateInstance(mapping));
            }
        }
Exemplo n.º 8
0
 protected override void Load(ContainerBuilder builder)
 {
     // Register the common thing once, not in each module.
     builder.RegisterType <MappingEngine>().As <IMappingEngine>();
     // Here's where you dynamically get all the registered profiles
     // and add them at the same time to the config store.
     builder.Register(ctx =>
     {
         var profiles    = ctx.Resolve <IEnumerable <Profile> >();
         var configStore = new ConfigurationStore
                               (new TypeMapFactory(), MapperRegistry.AllMappers());
         foreach (var profile in profiles)
         {
             configStore.AddProfile(profile);
         }
         return(configStore);
     })
     .AsImplementedInterfaces()
     .SingleInstance();
 }