Skip to content

Instantly share code, notes, and snippets.

@gethari
Last active July 19, 2019 06:07
Show Gist options
  • Save gethari/5a58a4ade90be08808af6a306bfddb28 to your computer and use it in GitHub Desktop.
Save gethari/5a58a4ade90be08808af6a306bfddb28 to your computer and use it in GitHub Desktop.
public class AutoMapperModule: Module {
protected override void Load(ContainerBuilder builder) {
builder.RegisterAssemblyTypes(typeof(AutoMapperModule).Assembly).As < Profile > ();
builder.Register(context => new MapperConfiguration(cfg => {
foreach(var profile in context.Resolve < IEnumerable < Profile >> ()) {
cfg.AddProfile(profile);
}
})).AsSelf().SingleInstance();
builder.Register(c => c.Resolve < MapperConfiguration > ().CreateMapper(c.Resolve))
.As < IMapper > ()
.InstancePerLifetimeScope();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment