Autofac - 注册按类型的插件 [英] Autofac - Register plugins by type
问题描述
我正在写一个插件系统:每一个插件是在自己组装必须由autofac被加载,并通过与设置插件的类型参数的属性签署。我能在我的asp.net MVC应用程序插件按类型来解决,我该怎么办呢?每个插件由一个抽象类,覆盖predefinited方法inhrerit。
I'm writing a plugin system: every plugin is in his own assembly that must be loaded by autofac and is signed by an attribute with a parameter that set the type of plugin. I would be able to resolve in my asp.net mvc app the plugins by type, how can I do this? Every plugin inhrerit by an abstract class and override predefinited methods.
推荐答案
RegisterAssemblyTypes()
可能是起点,你后:
Assembly[] assembliesWithPlugins = // find these somehow
var builder = new ContainerBuilder();
builder.RegisterAssemblyTypes(assembliesWithPlugins)
.AssignableTo<MyAbstractPluginType>()
.WithMetadata(t => GetPluinTypeFromMyAttribute(t));
一旦你注册您的插件这种方式,Autofac的元数据支持将允许您使用它们(的 HTTP://$c$c.google.com/p/autofac/wiki/Metadata A>)。我presume从你的一些问题以后,你已经走向了这条路。
Once you've registered your plug-ins this way, Autofac's Metadata support will allow you to consume them (http://code.google.com/p/autofac/wiki/Metadata). I presume from some of your later questions that you're already heading down this path.
祝你好运吧。
尼克
Good luck with it. Nick
这篇关于Autofac - 注册按类型的插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!