How to load a DLL from a directory using the MEF (Managed Extensibility Framework)

I am currently working with MEF and run into some problems.

I want to load a DLL from a directory.

first scan the directory and save two things in the dictionary

The name of the property from the corresponding DLL (as a string)

and module name (as a string)

here is the ScanDirectory () code

private void ScanPluginDirectory()
{
    catalog = new AggregateCatalog();

    catalog.Catalogs.Add(new DirectoryCatalog(@"..\..\plugin"));            
    container = new CompositionContainer(catalog);

    batch = new CompositionBatch();
    batch.AddPart(this);        

    container.Compose(batch);    

    pluginDictionary = new Dictionary<String, String>();
    foreach (IFilter filter in filters)
    {
        Type t = filter.GetType();
        pluginDictionary.Add(filter.Name, t.Module.Name);
    }
}

and show your name in the checkbox list. when choosing dll from the checkbox.

I have an import statement like

[Import]
public IEnumerable<IFilter> filters { get; set; }

currently my program is working fine. what i did when i check the plugin from the checkbox list. it moves it to the "loaded" directory, and they QueryPlugin () access the "loaded" directory to search for plugins.

when unchecking the checkbox. I get it out of the "loaded" directory ...

batch.RemovePart(), DLL .

. ,

batch.AddPart(new DemoFilter1());

DirectoryCatalog();;

+3
1

DirectoryCatalog AggregateCatalog AssemblyCatalog . , , AssemblyCatalog AggregateCatalog.

, , . .

+3

Source: https://habr.com/ru/post/1708538/


All Articles