简体   繁体   English

我可以使用MEF在Monorail中加载控制器吗?

[英]Can I load controllers in Monorail using MEF?

I've used MEF for a few projects at work and I've just stared messing about with Monorail in my spare time. 我在一些工作中使用了MEF,而在业余时间我只是盯着Monorail。 I was wondering if there was any way that I could use MEF to load the controllers that Monorail uses. 我想知道是否可以使用MEF加载Monorail使用的控制器。 Monorail appears to look for controllers in assemblies that you list in the Web.Config: Monorail似乎在您在Web.Config中列出的程序集中寻找控制器:

<controllers>
  <assembly>my.assembly</assembly>
</controllers>

Is there a way that 'my.assembly' can then use MEF to load up more controllers? 有没有一种方法可以使“ my.assembly”随后使用MEF加载更多的控制器? 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. Monorail是一个非常可扩展的框架。 Almost everything is being provided by a service that can be easily switched with something else. 几乎所有内容都由可以通过其他方式轻松切换的服务提供。 For eg, IoC integration is quite easy, as you can switch the services that creates controllers, filters, helpers, and all other MonoRail entities. 例如,IoC集成非常容易,因为您可以切换创建控制器,过滤器,助手和所有其他MonoRail实体的服务。

Concrete example: Integrating Windsor container into Monorail 具体示例: 将Windsor容器集成到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. 如果您只希望由MEF提供控制器,那么工作量就更少了。

I have very little working knowledge of MEF so it might be a little off, but you'd get the general idea: 我对MEF的工作知识很少,因此可能会有一些不足,但是您会得到一个大概的想法:

  1. Use MEF discovery mechanisms to locate controller types, then add controller types to the default IControllerTree service. 使用MEF发现机制查找控制器类型,然后将控制器类型添加到默认的IControllerTree服务。 take a peek at MonoRailFacility.cs for inspiration. MonoRailFacility.cs以获得灵感。
  2. Implement a MefControllerFactory : IControllerFactory that will use MEF to instantiate controllers when needed. 实现一个MefControllerFactory : IControllerFactory ,将在需要时使用MEF实例化控制器。 Inspiration is at WindsorControllerFactory.cs 灵感来自WindsorControllerFactory.cs

您还不能使用它,但可以在Hammett的博客中查看该文章,他其中谈论他正在为MonoRail 3.0进行原型制作(默认情况下包括对MEF的支持)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM