带有 NinjectHttpApplication 和 MEF 的 Asp Mvc 3
我使用 Ninject 作为我的 MVC 控制器工厂,但我还通过 MEF 加载某些路由和控制器,这些控制器需要能够向 Ninject 注册自己:
Bind<SomePluginController>.ToSelf();
因此可以选取动态添加的路由。
到目前为止,我能想到的唯一方法是将内部内核暴露在 Web 应用程序之外,但这似乎有点令人讨厌,而且 NinjectHttpApplication.Kernel
似乎已经过时了。
还有其他人设法做到这一点吗?
I am using Ninject as my MVC controller factory, but I also load in certain routes and controllers via MEF, these controllers need to be able to register themselves with Ninject:
Bind<SomePluginController>.ToSelf();
So the dynamically added routes can be picked up.
So far the only way to do this I can think of is to expose the internal kernel outside of the web application, however this seems a bit nasty and the NinjectHttpApplication.Kernel
seems to be obsolete.
Has anyone else managed to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您遇到的问题是 MEF 被设计为组成一组未知部件,而 Ninject 正在处理显式组件注册。您无法轻松地从 MEF 获取类型信息,因为它都是在运行时而不是编译时处理的。
我认为您可能需要做的是构建一个支持 Ninject 和 MEF 的复合控制器工厂。
The problem you've got is that MEF is designed to compose a set of unknown parts, whereas Ninject is dealing with explicit component registration. You can't easily grab type information from MEF because it is all handled at runtime, not compile time.
What I think you may have to do, is build a composite controller factory that supports both Ninject and MEF.