Use classes from another MEF assembly without reference to it

I have 2 MEF components. Let it be component A and component B.

I need to have access to a class from component B in component A without reference to it. Then I would like to instantiate the class object manually.

Currently, I see that MEF allows you to automatically create objects using [Import]. It uses the interface to be referenced.

Can data types from other assemblies be used without reference to it? Is there such a mechanism supported by MEF?

+3
source share
3 answers

There are several ways to do this.

, . PublicInterfaces, , A ( B A, ).

B .

B . B AssemblyCatalog, DirectoryCatalog , B.

A GetExportedValue<T>() . :

// Known by A and B
public interface CommonInterface 
{
   // ...
}

// In B, not A
[Export(typeof(CommonInterface))]
public class BClass : CommonInterface
{
   // ...
}

// In A where you want to manually create class B
CommonInterface objB = _container.GetExportedValue<CommonInterface>();
0

, . MEF.

+1

Then I would like to instantiate the class object manually.

Perhaps you would be better off doing this manually by loading the assembly and selecting the type you want from it, instead of using MEF.

0
source

All Articles