Skip to content

Instantly share code, notes, and snippets.

@ajai8085
Created April 12, 2016 05:34
Show Gist options
  • Save ajai8085/84a996cc09d866253d6ecaa24be44d7e to your computer and use it in GitHub Desktop.
Save ajai8085/84a996cc09d866253d6ecaa24be44d7e to your computer and use it in GitHub Desktop.
Automapper 4.2 and Autofac Setup
internal class AutomapperConfigurationProfile : Profile
{
protected override void Configure()
{
CreateMap<Source,Destination>().ForMember(dest=>dest.Field1,opts=> opts.MapFrom(src=>(int)src.Fieldxx));
CreateMap<Abc,Xyz>().ReverseMap();
...
Mapping here
}
}
}
public class DefaultModule : Module
{
protected override void Load(ContainerBuilder builder)
{
builder.Register(c =>
{
var mapperConfigruation = new MapperConfiguration(cfg => cfg.AddProfile(new AutomapperConfigurationProfile()));
mapperConfigruation.AssertConfigurationIsValid();
var mappings = mapperConfigruation.CreateMapper();
return mappings;
}).As<IMapper>().SingleInstance();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment