asp.net mvc - A dependency injection Exception with Postal and Unity -
in asp.net web mvc controller (v5.1), wanted switch using iemailservice on postal (v0.9.1), did following on controller:
public class homecontroller : controller { private readonly iemailservice _emailservice; public homecontroller(iemailservice emailservice) { if (emailservice == null) throw new argumentnullexception("emailservice"); _emailservice = emailservice; } }
my unity (v3.0) container setup:
container.registertype<iemailservice, emailservice>(); container.registertype<iemailviewrenderer, emailviewrenderer>(); container.registertype<iemailparser, emailparser>();
but exception, can't make sense out of.
unity trying tell me?
the type ilist`1 not have accessible constructor.
stack trace:
[invalidoperationexception: type ilist`1 not have accessible constructor.] microsoft.practices.objectbuilder2.dynamicmethodconstructorstrategy.throwfornullexistingobject(ibuildercontext context) +239 lambda_method(closure , ibuildercontext ) +60 microsoft.practices.objectbuilder2.<>c__displayclass1.<getbuildmethod>b__0(ibuildercontext context) +71 microsoft.practices.objectbuilder2.dynamicmethodbuildplan.buildup(ibuildercontext context) +42 microsoft.practices.objectbuilder2.buildplanstrategy.prebuildup(ibuildercontext context) +333 microsoft.practices.objectbuilder2.strategychain.executebuildup(ibuildercontext context) +274 microsoft.practices.objectbuilder2.buildercontext.newbuildup(namedtypebuildkey newbuildkey) +250 microsoft.practices.unity.objectbuilder.namedtypedependencyresolverpolicy.resolve(ibuildercontext context) +101 lambda_method(closure , ibuildercontext ) +205 microsoft.practices.objectbuilder2.<>c__displayclass1.<getbuildmethod>b__0(ibuildercontext context) +71 microsoft.practices.objectbuilder2.dynamicmethodbuildplan.buildup(ibuildercontext context) +42 microsoft.practices.objectbuilder2.buildplanstrategy.prebuildup(ibuildercontext context) +333 microsoft.practices.objectbuilder2.strategychain.executebuildup(ibuildercontext context) +274 microsoft.practices.objectbuilder2.buildercontext.newbuildup(namedtypebuildkey newbuildkey) +250 microsoft.practices.unity.objectbuilder.namedtypedependencyresolverpolicy.resolve(ibuildercontext context) +101 lambda_method(closure , ibuildercontext ) +205 microsoft.practices.objectbuilder2.<>c__displayclass1.<getbuildmethod>b__0(ibuildercontext context) +71 microsoft.practices.objectbuilder2.dynamicmethodbuildplan.buildup(ibuildercontext context) +42 microsoft.practices.objectbuilder2.buildplanstrategy.prebuildup(ibuildercontext context) +333 microsoft.practices.objectbuilder2.strategychain.executebuildup(ibuildercontext context) +274 microsoft.practices.objectbuilder2.buildercontext.newbuildup(namedtypebuildkey newbuildkey) +250 microsoft.practices.unity.objectbuilder.namedtypedependencyresolverpolicy.resolve(ibuildercontext context) +101 lambda_method(closure , ibuildercontext ) +231 microsoft.practices.objectbuilder2.<>c__displayclass1.<getbuildmethod>b__0(ibuildercontext context) +71 microsoft.practices.objectbuilder2.dynamicmethodbuildplan.buildup(ibuildercontext context) +42 microsoft.practices.objectbuilder2.buildplanstrategy.prebuildup(ibuildercontext context) +333 microsoft.practices.objectbuilder2.strategychain.executebuildup(ibuildercontext context) +274 microsoft.practices.objectbuilder2.buildercontext.newbuildup(namedtypebuildkey newbuildkey) +250 microsoft.practices.unity.objectbuilder.namedtypedependencyresolverpolicy.resolve(ibuildercontext context) +101 lambda_method(closure , ibuildercontext ) +209 microsoft.practices.objectbuilder2.<>c__displayclass1.<getbuildmethod>b__0(ibuildercontext context) +71 microsoft.practices.objectbuilder2.dynamicmethodbuildplan.buildup(ibuildercontext context) +42 microsoft.practices.objectbuilder2.buildplanstrategy.prebuildup(ibuildercontext context) +333 microsoft.practices.objectbuilder2.strategychain.executebuildup(ibuildercontext context) +274 microsoft.practices.unity.unitycontainer.dobuildup(type t, object existing, string name, ienumerable`1 resolveroverrides) +383 [resolutionfailedexception: resolution of dependency failed, type = "postaltest.controllers.homecontroller", name = "(none)". exception occurred while: while resolving. exception is: invalidoperationexception - type ilist`1 not have accessible constructor. ----------------------------------------------- @ time of exception, container was: resolving postaltest.controllers.homecontroller,(none) resolving parameter "emailservice" of constructor postaltest.controllers.homecontroller(postal.iemailservice emailservice) resolving postal.emailservice,(none) (mapped postal.iemailservice, (none)) resolving parameter "emailviewrenderer" of constructor postal.emailservice(postal.iemailviewrenderer emailviewrenderer, postal.iemailparser emailparser, system.func`1[[system.net.mail.smtpclient, system, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089]] createsmtpclient) resolving postal.emailviewrenderer,(none) (mapped postal.iemailviewrenderer, (none)) resolving parameter "viewengines" of constructor postal.emailviewrenderer(system.web.mvc.viewenginecollection viewengines) resolving system.web.mvc.viewenginecollection,(none) resolving parameter "list" of constructor system.web.mvc.viewenginecollection(system.collections.generic.ilist`1[[system.web.mvc.iviewengine, system.web.mvc, version=5.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35]] list) resolving system.collections.generic.ilist`1[system.web.mvc.iviewengine],(none) ] microsoft.practices.unity.unitycontainer.dobuildup(type t, object existing, string name, ienumerable`1 resolveroverrides) +446 microsoft.practices.unity.unitycontainer.dobuildup(type t, string name, ienumerable`1 resolveroverrides) +50 microsoft.practices.unity.unitycontainer.resolve(type t, string name, resolveroverride[] resolveroverrides) +48 microsoft.practices.unity.unitycontainerextensions.resolve(iunitycontainer container, type t, resolveroverride[] overrides) +61 unity.mvc5.unitydependencyresolver.getservice(type servicetype) +140 system.web.mvc.defaultcontrolleractivator.create(requestcontext requestcontext, type controllertype) +87 [invalidoperationexception: error occurred when trying create controller of type 'postaltest.controllers.homecontroller'. make sure controller has parameterless public constructor.] system.web.mvc.defaultcontrolleractivator.create(requestcontext requestcontext, type controllertype) +247 system.web.mvc.defaultcontrollerfactory.getcontrollerinstance(requestcontext requestcontext, type controllertype) +438 system.web.mvc.defaultcontrollerfactory.createcontroller(requestcontext requestcontext, string controllername) +226 system.web.mvc.mvchandler.processrequestinit(httpcontextbase httpcontext, icontroller& controller, icontrollerfactory& factory) +326 system.web.mvc.mvchandler.beginprocessrequest(httpcontextbase httpcontext, asynccallback callback, object state) +157 system.web.mvc.mvchandler.beginprocessrequest(httpcontext httpcontext, asynccallback callback, object state) +88 system.web.mvc.mvchandler.system.web.ihttpasynchandler.beginprocessrequest(httpcontext context, asynccallback cb, object extradata) +50 system.web.callhandlerexecutionstep.system.web.httpapplication.iexecutionstep.execute() +301 system.web.httpapplication.executestep(iexecutionstep step, boolean& completedsynchronously) +155
i don't use unity, register instance of email service instead?
container.registerinstance<iemailservice>(new emailservice());
Comments
Post a Comment