简体   繁体   English

在WCF客户端服务中使用MEF导入的共享方法

[英]Sharing methods imported using MEF in WCF client service

I am using the following code to successfully load a plugin in my WCF client service main class: 我正在使用以下代码在我的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);
    }

And call a method using: 并使用以下方法调用方法:

PluginCompose(loadPluginTarget); PluginCompose(loadPluginTarget); PluginService.HelloWorld("Something"); PluginService.HelloWorld(“ Something”);

How do I make the plugin dll methods available in the class which implements callback interface of the duplex contract? 如何在实现双工合同的回调接口的类中使插件dll方法可用?

Do I need call PluginCompose() everytime before calling a method in my plugin dll? 在插件dll中调用方法之前,是否需要每次都调用PluginCompose()?

You need to compose (inject the dependencies) the components, without that your pluggings are not available for use. 您需要组成(注入依赖项)组件,否则,您的插件将无法使用。 You can either put that in your constructor, or some other method to initialize the components for you on first call. 您可以将其放在构造函数中,也可以使用其他方法在首次调用时为您初始化组件。

In other words, this is what loads and make your plugins work and become available for use, so you need to make this little bit of magic happen before you start to use your plugins, oh and you may wish to use using 换句话说,这就是加载并使您的插件正常工作并可供使用的原因,因此,在开始使用插件之前,您需要使这神奇的事情发生,哦,您可能希望using

using(var catalog = new DirectoryCatalog(targetPath))
using(var container = new CompositionContainer(catalog))
{
    container.ComposeParts(this);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM