asp.net mvc - Autofac DI .NET MVC controllers without default constructor -
when use ajax queries asp.net mvc controller have error: type 'web.implementation.controllers.mycontroller' not have default constructor.
my code:
//in controller private idataservice dataservice; //i try delete constructor, //because use di , don't want create currentcontext , dataservice. public mycontroller() { var currentcontext = new currentcontext(); dataservice = new dataservice(currentcontext); } public mycontroller(idataservice dataservice) { dataservice = dataservice; } //in autofac init builder.registertype<dataservice>().as <idataservice>();
how can use autofac di in case ? me please.
upd:
//in global.asax dependencyconfigure.initialize(); //in dependencyconfigure class public static void initialize() { var builder = new containerbuilder(); dependencyresolver.setresolver( new dependency(registerservices(builder)) ); }
Comments
Post a Comment