asp.net mvc - Manually create controllers in MVC 6 with custom IControllerFactory implementation -


based on that post created custom controller factory instantiating controllers based on logic (for making pluggable architecture).

for test purposes kinda hard-coded.

var controller = bootstrapper.getinstance<controller>("testmoduleapi");  actioncontext.routedata.values["controller"] = "testmoduleapi"; actioncontext.routedata.values["action"] = "get"; var returncontroller = _controlleractivator.create(actioncontext, controller.gettype());  return returncontroller; 

boostrapper.getinstance() gets controller instance mef folder exported controllers.

when open default route home/index code goes through here , returncontroller variable instance of desired controller. though error saying

an unhandled exception occurred while processing request.  invalidoperationexception: view 'index' not found. following locations searched: /views/testmoduleapi/index.cshtml /views/shared/index.cshtml. 

i've tried simple approach make createcontroller return whatever want:

actioncontext.routedata.values["controller"] = "myapi"; actioncontext.routedata.values["action"] = "get";  return new myapicontroller(); 

here overriding every call createcontroller return myapicontroller instance. in case myapicontroller inherits homeapicontroller. still when go /api/homeapi/get example values homeapicontroller, not myapicontroller.

how possible in custom icontrollerfactory implementation instantiate whatever controller instance want?

update: when debugging first code can see constructor of testmoduleapicontroller called, get action never called.


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -