我可以使用 MEF 在单轨列车中加载控制器吗?
我在工作中使用过 MEF 来完成一些项目,并且在业余时间开始尝试使用 Monorail。我想知道是否有任何方法可以使用 MEF 加载单轨铁路使用的控制器。 Monorail 似乎会在 Web.Config 中列出的程序集中查找控制器:
<controllers>
<assembly>my.assembly</assembly>
</controllers>
有没有办法让 'my. assembly' 使用 MEF 加载更多控制器?我必须承认我还没有想到我需要这个功能的原因,但我只是在尝试!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您还不能使用它,但请查看 Hammett 的博客文章此处,其中他谈论了他正在为 MonoRail 3.0 设计的原型(包括默认支持 MEF)。
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).
Monorail 是一个非常可扩展的框架。几乎所有内容都是由可以轻松地与其他服务切换的服务提供的。
例如,IoC 集成非常简单,因为您可以切换创建控制器、过滤器、助手和所有其他 MonoRail 实体的服务。
具体示例:将 Windsor 集装箱集成到单轨铁路中
现在,单轨铁路中的几乎所有内容都将由 Windsor 提供。如果您只希望 MEF 提供控制器,那么工作量就更少了。
我对 MEF 的工作知识知之甚少,所以可能有点偏差,但您会得到总体思路:
IControllerTree
服务。查看MonoRailFacility.cs
获取灵感。MefControllerFactory : IControllerFactory
,它将在需要时使用 MEF 实例化控制器。灵感来自WindsorControllerFactory.cs
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:
IControllerTree
service. take a peek atMonoRailFacility.cs
for inspiration.MefControllerFactory : IControllerFactory
that will use MEF to instantiate controllers when needed. Inspiration is atWindsorControllerFactory.cs