c# - How to import only types, not instances? -


i'm importing dlls export iplugin class using mef (system.componentmodel.composition) [importmany(typeof(iplugin))] attribute.

here's code use fetch extensions:

aggregatecatalog catalog = new aggregatecatalog(); catalog.catalogs.add(new assemblycatalog(assembly.getexecutingassembly())); catalog.catalogs.add(new directorycatalog(appdatahelper.exedir + "/module/")); compositioncontainer container = new compositioncontainer(catalog); compositionbatch batch = new compositionbatch(); batch.addpart(this); 

however, far see, corresponding property hold instances afterwards.

how import types (preferrably type objects) of extensions can create instances myself?

you can't, mef works creating single instance of every compatible , exported type finds.

the easiest way around import factories , use them create actual instances.

the interface like:

interface ipluginfactory {     iplugin createinstance();     string typename {get;} } 

and search mef populated collection of factories right type name , call createinstance function.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -