开发者

Can I load controllers in Monorail using MEF?

开发者 https://www.devze.com 2023-01-16 20:46 出处:网络
I\'ve used MEF for a few projects at work and I\'ve just stared messing about with Monorail in my spare time. I was wondering if there was any way that I could use MEF to load the controllers that Mon

I've used MEF for a few projects at work and I've just stared messing about with Monorail in my spare time. I was wondering if there was any way that I could use MEF to load the controllers that Monorail uses. Monorail appears to look for controllers in assemblies that you list in the Web.Config:

<controllers>
  <assembly>my.assembly</assembly>
</controllers>
开发者_如何转开发

Is there a way that 'my.assembly' can then use MEF to load up more controllers? I have to admit I haven't though of a reason I would need this functionality but I'm just trying things out!


Monorail is a very extensible framework. Almost everything is being provided by a service that can be easily switched with something else. For e.g., IoC integration is quite easy, as you can switch the services that creates controllers, filters, helpers, and all other MonoRail entities.

Concrete example: Integrating Windsor container into Monorail

Now this sets up almost everything in the Monorail to be provided by Windsor. If you only want Controllers to be provided by MEF, there's even less work.

I have very little working knowledge of MEF so it might be a little off, but you'd get the general idea:

  1. Use MEF discovery mechanisms to locate controller types, then add controller types to the default IControllerTree service. take a peek at MonoRailFacility.cs for inspiration.
  2. Implement a MefControllerFactory : IControllerFactory that will use MEF to instantiate controllers when needed. Inspiration is at WindsorControllerFactory.cs


It's not something you can use yet, but have a look at Hammett's blog post here, where he talks about what he is prototyping for MonoRail 3.0 (including support for MEF by default).

0

精彩评论

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

关注公众号