c# - Automapper and Autofac -
i trying automapper play nice autofac in asp.net mvc application.
i have followed instructions in answer this: autofac 3 , automapper
however fails on first call _mapper.map<>(...)
autofac setup this:
builder.registertype<entitymappingprofile>().as<profile>(); builder.register(ctx => new configurationstore(new typemapfactory(), mapperregistry.mappers)) .asimplementedinterfaces() .singleinstance() .onactivating(x => { foreach (var profile in x.context.resolve<ienumerable<profile>>()) { x.instance.addprofile(profile); } }); builder.registertype<mappingengine>().as<imappingengine>();
and in business layer have service this:
public class linkservice : ilinkservice { private readonly ilinkrepository _linkrepository; private readonly imappingengine _mapper; public linkservice(ilinkrepository linkrepository, imappingengine mapper) { _linkrepository = linkrepository; _mapper = mapper; } public ienumerable<linkentity> get() { var links = _linkrepository.get().tolist(); return _mapper.map<ienumerable<link>, ienumerable<linkentity>>(links); } public linkentity getbyid(int id) { var link = _linkrepository.getbyid(id); return _mapper.map<link, linkentity>(link); } }
the call _mapper.map<ienumerable<link>, ienumerable<linkentity>>
fails with:
missing type map configuration or unsupported mapping.
any ideas might going wrong?
you're missing creating mapper, create map link linkentity in entitymappingprofile:
internal class entitymappingprofile :profile { protected override void configure() { base.configure(); this.createmap<link, linkentity>(); } }
Comments
Post a Comment