Skip to content

Instantly share code, notes, and snippets.

@martijnburgers
Last active December 31, 2015 22:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martijnburgers/8053405 to your computer and use it in GitHub Desktop.
Save martijnburgers/8053405 to your computer and use it in GitHub Desktop.
Our AutoMapper registry for AutoMapper 2.2.1
/// <summary>
/// Registry class responsible for registering automapper types in the IoC container.
/// </summary>
public class AutomapperRegistry : Registry
{
public AutomapperRegistry()
{
For<ConfigurationStore>().Singleton().Use<ConfigurationStore>().Ctor<IEnumerable<IObjectMapper>>().Is(MapperRegistry.AllMappers());
For<IConfigurationProvider>().Use(ctx => ctx.GetInstance<ConfigurationStore>());
For<IConfiguration>().Use(ctx => ctx.GetInstance<ConfigurationStore>());
For<ITypeMapFactory>().Use<TypeMapFactory>();
For<IMappingEngine>().Singleton().Use<MappingEngine>();
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());
});
}
}
@martijnburgers
Copy link
Author

The AutoMapperProfileConvention class can be found here: https://gist.github.com/martijnburgers/8053310

Also checkout the bootstrapper: https://gist.github.com/martijnburgers/8054222

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment