Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.