c# - Create map with DBContext lookup, using automapper and ninject -
so i'm trying use dbcontext information db mapping.
so create custom typeconverter:
public class roundvmtotrampetround : itypeconverter<roundvm, trampetround> { public roundvmtotrampetround(dbtariff context) { this.context = context; } private dbtariff context { get; set; } public trampetround convert(resolutioncontext context) { roundvm source = (roundvm)context.sourcevalue; mapper.createmap<roundvm, trampetround>(); var dest = mapper.map<trampetround>(source); dest.difficulty = this.context.difficultytrampet.find(source.id); return dest; } }
and in controller create mapper using:
mapper.createmap<roundvm, trampetround>().convertusing<roundvmtotrampetround>();
but when mapping error message saying there no default constructor. want ninject me code:
kernel.bind<dbtariff>().toself().inrequestscope();
an answer here still same problem automapper + ef4 + asp.net mvc - getting 'context disposed' error (i know why, how fix it?)
i have tried solution given in link same error. how automapper use ninject fix problem?
edit
i found same thing done autofac http://thoai-nguyen.blogspot.se/2011/10/autofac-automapper-custom-converter-di.html guess need tell automapper use ninject resolver how , where?
all information need given in blog article linked. break down absolute minimum information, need do:
mapper.initialize(x => { x.constructservicesusing(type => kernel.get(type)); });
before ever access other mapper.
property / method, need call mapper.initialize(..)
before mapper.createmap
.
Comments
Post a Comment