开发者

Autofac - Register plugins by type

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 t开发者_JAVA百科his? Every plugin inhrerit by an abstract class and override predefinited methods.


RegisterAssemblyTypes() is probably the starting point you're after:

Assembly[] assembliesWithPlugins = // find these somehow
var builder = new ContainerBuilder();
builder.RegisterAssemblyTypes(assembliesWithPlugins)
    .AssignableTo<MyAbstractPluginType>()
    .WithMetadata(t => GetPluinTypeFromMyAttribute(t));

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


Personally I would use MEF for this and use Autofac's MEF integration.


Create a Autofac.Module in every plugin assembly. Register your plugin stuff there, and from your main application load your plugin dlls, look for Modules, register in container. Then resolve and have fun ;).

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜