Autofac + OWIN + Web Api ASP.NET MVC constructor injection not working -
i have webapicontroller no default constructor , after infoke receive error:
<error><message>an error has occurred.</message><exceptionmessage>an error occurred when trying create controller of type 'lookupscontroller'. make sure controller has parameterless public constructor.</exceptionmessage><exceptiontype>system.invalidoperationexception</exceptiontype><stacktrace> en system.web.http.dispatcher.defaulthttpcontrolleractivator.create(httprequestmessage request, httpcontrollerdescriptor controllerdescriptor, type controllertype) en system.web.http.controllers.httpcontrollerdescriptor.createcontroller(httprequestmessage request) en system.web.http.dispatcher.httpcontrollerdispatcher.<sendasync>d__1.movenext()</stacktrace><innerexception><message>an error has occurred.</message><exceptionmessage>el tipo 'ta.webapp.mvcapp.controllers.lookupscontroller' no tiene un constructor predeterminado</exceptionmessage><exceptiontype>system.argumentexception</exceptiontype><stacktrace> en system.linq.expressions.expression.new(type type) en system.web.http.internal.typeactivator.create[tbase](type instancetype) en system.web.http.dispatcher.defaulthttpcontrolleractivator.getinstanceoractivator(httprequestmessage request, type controllertype, func`1& activator) en system.web.http.dispatcher.defaulthttpcontrolleractivator.create(httprequestmessage request, httpcontrollerdescriptor controllerdescriptor, type controllertype)</stacktrace></innerexception></error>
this configuration invoked startup class:
public static void configurecontainer(iappbuilder app, assembly mvcapplicationassembly) { var builder = new containerbuilder(); var config = new httpconfiguration(); builder.registerapicontrollers(mvcapplicationassembly).propertiesautowired(); builder.registercontrollers(mvcapplicationassembly).propertiesautowired(); builder.registerwebapifilterprovider(config); builder.registerfilterprovider(); builder.registersource(new viewregistrationsource()); builder.registermodule(new configurationsettingsreader("autofac")); var container = builder.build(); config.dependencyresolver = new autofacwebapidependencyresolver(container); dependencyresolver.setresolver(new autofacdependencyresolver(container)); app.useautofacmiddleware(container); app.useautofacwebapi(config); app.usewebapi(config); app.useautofacmvc(); }
i had reviewed configuration 1 thousand times , followed documentation can't see problem.
i have other controller mvc same parameter type in constructor , works perfect.
any appreciated.
edited: code iregistration registered:
protected override void load(containerbuilder builder) { builder.registertype<registrationservicefacade>() .as<iregistration>(); }
this code inside autofac module.
Comments
Post a Comment