让 AsyncController 与 Ninject 一起工作
我正在尝试将控制器中的某些操作转换为在使用 ninject 进行依赖项注入的 mvc 项目中异步运行。我按照以下步骤继承 AsyncController 并将与“X”操作对应的方法更改为“XAsync”和“XCompleted”,但异步操作未得到解决。我确信这个问题与 ninject 有关。我尝试将 ninject 的控制器操作调用器显式设置为 'AsyncControllerActionInvoker':
Bind
但没有运气。有没有人设法让异步操作与 ninject 一起工作?
干杯,
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,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
本质上,我面临的问题是 ninject 使用的默认操作调用程序不支持异步操作,当您尝试在控制器中设置操作调用程序时,默认的 ninjectControllerFactory 会覆盖它。我采取了以下步骤来解决问题:
1.在注入映射中,我添加了以下关联:
2.我创建了一个自定义控制器工厂,它基本上是 ninject 的控制器工厂,唯一的区别是它不会覆盖操作调用程序。
3.在 OnApplicationStarted() 方法中,我将控制器工厂设置为我的自定义工厂:
希望这会有所帮助。
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.
经过大量搜索后,我意识到除此之外,每个控制器都需要明确设置为使用支持异步操作的操作调用程序。
After much search i realized in addition to this, each controller needs to explicitly be set to use an Action Invoker that supports Async Actions.