c# - How to inject a service in AutoMapper Profile class? -


i working on project have automapper profile class has mappings. however, reason, need call service , in order call service, need call inject service in profile class.

so class looks following:

public class myclass : profile {  public myclass {    //somemapping here }  } 

now, want inject service, needs take service in constructor , constructor following:

public myclass(iservice service)     {        //somemapping here     } 

now,

services.addautomapper(); 

calls classes inherit profile class auto magically, , not call parameter constructor.

now question best way call service in automapper profile class?

addautomapper() extension method synthatic sugar. needs can initialize automapper manually:

mapper.initialize(cfg => {    cfg.addprofile(new myclass()); }); 

https://github.com/automapper/automapper/wiki/configuration#assembly-scanning-for-auto-configuration

maybe solve issues.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -