开发者

Using the Mef to have plugin override Core interface

We are investigating using MEF for a plugin/IoC solution.

The concept is that the Core project is a working instance. The plugin will then replace any Expo开发者_开发知识库rts in the Core that it contains.

var catalog = new AggregateCatalog(
          new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly()),
          new DirectoryCatalog("Plugin"));

How do I have the Plugin catalog overwrite the existing Assembly catalog export?


In this example, any exports found in the plugin subfolder will override the exports found in the application folder. It works by passing multiple export providers to the CompositionContainer. The first export provider will take precedence.

var defaultExportProvider = 
    new CatalogExportProvider(new DirectoryCatalog(".","*"));
var pluginExportProvider = 
    new CatalogExportProvider(new DirectoryCatalog(@".\plugin"));
var container = new CompositionContainer(
    pluginExportProvider, defaultExportProvider);
defaultExportProvider.SourceProvider = container;
pluginExportProvider.SourceProvider = container;
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜