简体   繁体   中英

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:

    [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); PluginService.HelloWorld("Something");

How do I make the plugin dll methods available in the class which implements callback interface of the duplex contract?

Do I need call PluginCompose() everytime before calling a method in my plugin dll?

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(var catalog = new DirectoryCatalog(targetPath))
using(var container = new CompositionContainer(catalog))
{
    container.ComposeParts(this);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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