c# - How to register an AutoMapper profile with Unity -


i have following automapper profile:

public class automapperbootstrap : profile {     protected override void configure()     {         createmap<data.entityframework.rssfeed, irssfeed>().formember(x => x.newsarticles, opt => opt.mapfrom(y => y.rssfeedcontent));         createmap<irssfeedcontent, data.entityframework.rssfeedcontent>().formember(x => x.id, opt => opt.ignore());     } } 

and initializing this:

var config = new mapperconfiguration(cfg => {        cfg.addprofile(new automapperbootstrap()); });  container.registerinstance<imapper>("mapper", config.createmapper()); 

when try inject in constructor:

private imapper _mapper; public rsslocalrepository(imapper mapper) {     _mapper = mapper; } 

i recieve following error:

the current type, automapper.imapper, interface , cannot constructed. missing type mapping?

how can initialize automapper profile unity, can use mapper anywhere through di?

in example creating named mapping:

// named mapping "mapper name" container.registerinstance<imapper>("mapper", config.createmapper()); 

but how resolver know name?

you need register mapping without name:

// named mapping "mapper name" container.registerinstance<imapper>(config.createmapper()); 

it map mapper instance imapper interface , instance returned on resolving interface


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -