Skip to content

Instantly share code, notes, and snippets.

@plioi
Created January 27, 2016 00:02
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 plioi/27af636fec78792dfbb2 to your computer and use it in GitHub Desktop.
Save plioi/27af636fec78792dfbb2 to your computer and use it in GitHub Desktop.
public class AutoMapperBootstrapper
{
private static readonly Lazy<AutoMapperBootstrapper> Bootstrapper = new Lazy<AutoMapperBootstrapper>(InternalInitialize);
public static void Initialize()
{
var bootstrapper = Bootstrapper.Value;
}
private AutoMapperBootstrapper()
{
}
private static AutoMapperBootstrapper InternalInitialize()
{
var profiles = typeof(AutoMapperBootstrapper)
.Assembly
.GetTypes()
.Where(type => type.IsSubclassOf(typeof(Profile)))
.Select(Activator.CreateInstance)
.Cast<Profile>()
.ToArray();
Mapper.Initialize(cfg =>
{
foreach (var profile in profiles)
cfg.AddProfile(profile);
cfg.Seal();
});
return new AutoMapperBootstrapper();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment