Last active
August 4, 2016 20:17
-
-
Save martijnburgers/8053263 to your computer and use it in GitHub Desktop.
Our AutoMapper registry for AutoMapper 3.1.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Registry class responsible for registering automapper types in the IoC container. | |
/// </summary> | |
public class AutomapperRegistry : Registry | |
{ | |
public AutomapperRegistry() | |
{ | |
var platformSpecificRegistry = PlatformAdapter.Resolve<IPlatformSpecificMapperRegistry>(); | |
platformSpecificRegistry.Initialize(); //this will init all the standard mappers specific for this platform. | |
For<ConfigurationStore>().Singleton().Use<ConfigurationStore>().Ctor<IEnumerable<IObjectMapper>>().Is(MapperRegistry.Mappers); | |
For<IConfigurationProvider>().Use(ctx => ctx.GetInstance<ConfigurationStore>()); | |
For<IConfiguration>().Use(ctx => ctx.GetInstance<ConfigurationStore>()); | |
For<ITypeMapFactory>().Use<TypeMapFactory>(); | |
For<IMappingEngine>().Singleton().Use<MappingEngine>(); | |
SelectConstructor<MappingEngine>(() => new MappingEngine(null)); | |
Scan(scanner => | |
{ | |
//first decide which assemblies you want to scan | |
scanner.AssembliesFromApplicationBaseDirectory(); | |
scanner.With(new AutoMapperProfileConvention());//scan for automapper profile types | |
}); | |
Scan(scanner => | |
{ | |
//first decide which assemblies you want to scan | |
scanner.AssembliesFromApplicationBaseDirectory(); | |
scanner.ConnectImplementationsToTypesClosing(typeof(ITypeConverter<,>)).OnAddedPluginTypes(t => t.HybridHttpOrThreadLocalScoped()); | |
scanner.ConnectImplementationsToTypesClosing(typeof(ValueResolver<,>)).OnAddedPluginTypes(t => t.HybridHttpOrThreadLocalScoped()); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The AutoMapperProfileConvention class can be found here: https://gist.github.com/martijnburgers/8053310
Also checkout the bootstrapper: https://gist.github.com/martijnburgers/8054222