How does MEF manage to instantiate the exported part, which is the inner class of the external assembly?

My question is pretty simple, but unfortunately I haven't found an answer yet.

Using MEF , I can specify some internal export and import in the assembly of the class library as follows:

[Export] internal class SomeExport { } [ModuleExport(typeof(SomeModule))] internal class SomeModule : IModule { [ImportingConstructor] internal SomeModule(SomeExport instance) { } } 

My CompositionContainer is in the main EXE assembly, but somehow it manages to instantiate the SomeExport object inside the class library assembly so that I can use it. Usually my internal class libraries should not be accessible from an EXE assembly, but somehow I create my instances.

How it works?

+5
source share
1 answer

MEF usually uses reflection to detect parts and create them. Reflection is not limited to visibility internal or even private .

+6
source

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


All Articles