开发者

Asp Mvc 3 with NinjectHttpApplication and MEF

开发者 https://www.devze.com 2023-04-08 23:50 出处:网络
I am using Ninject as my MVC contr开发者_高级运维oller factory, but I also load in certain routes and controllers via MEF, these controllers need to be able to register themselves with Ninject:

I am using Ninject as my MVC contr开发者_高级运维oller 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号