Created
April 12, 2016 05:34
-
-
Save ajai8085/84a996cc09d866253d6ecaa24be44d7e to your computer and use it in GitHub Desktop.
Automapper 4.2 and Autofac Setup
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
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 | |
} | |
} | |
} |
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 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