1

我正在使用以下代码在我的 WCF 客户端服务主类中成功加载插件:

    [Import]
    public IBasePluginService PluginService { get; set; }


    public void PluginCompose(string targetPath)
    {
        var catalog = new DirectoryCatalog(targetPath);
        var container = new CompositionContainer(catalog);
        container.ComposeParts(this);
    }

并使用以下方法调用方法:

PluginCompose(loadPluginTarget); PluginService.HelloWorld("某事");

如何使插件 dll 方法在实现双工合约回调接口的类中可用?

在我的插件 dll 中调用方法之前,是否每次都需要调用 PluginCompose()?

4

1 回答 1

0

您需要组合(注入依赖项)组件,否则您的插件将无法使用。您可以将其放入构造函数中,也可以使用其他方法在第一次调用时为您初始化组件。

换句话说,这是加载并使您的插件工作并可供使用的内容,因此您需要在开始使用插件之前让这个小魔法发生,哦,您可能希望使用using

using(var catalog = new DirectoryCatalog(targetPath))
using(var container = new CompositionContainer(catalog))
{
    container.ComposeParts(this);
}
于 2013-08-26T21:03:04.250 回答