I am trying to convert some actions within a controller to run asynchronously in an mvc project that is using ninject for dependency injection. I’m following the steps by inheriting AsyncController and changing the methods that correspond to the ‘X’ action to ‘XAsync’ and ‘XCompleted’ but the async action is not getting resolved. I’m confident that the issue has to do with ninject. I have tried to explicitly set ninject’s Controller Action Invoker to ‘AsyncControllerActionInvoker’:
Bind<IActionInvoker>().To<AsyncControllerActionInvoker>().InSingletonScope();
but no luck. Has anyone managed to get Async actions working with ninject?
cheers,
Essentially the problem i was facing was that the default action invoker that is used by ninject doesnt support async actions and when you try to set the action invoker in a controller the default ninjectControllerFactory overrides it. I took the following steps to fix the problem:
1.In the injection mapping i added the following association:
2.I created a custom controller factory that is basically ninject’s controller factory with the only difference being that it doesn’t overwrite the action invoker.
3.In OnApplicationStarted() method I set the controller factory to my custom one:
Hope this helps.