Created
January 27, 2016 00:02
-
-
Save plioi/27af636fec78792dfbb2 to your computer and use it in GitHub Desktop.
This file contains 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
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