How does MEF manage to instantiate an exported part which is an internal class of an external assembly?
Asked Answered
C

1

8

My question is pretty simple, but unfortunately I could not find any answer yet.

Using MEF, I can specify some internal exports and imports in a class library assembly like that:

[Export]
internal class SomeExport
{ }

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

My CompositionContainer is located in the main EXE assembly, but somehow it manages to instantiate the SomeExport object inside the class library assembly so I can use it. Normally, my internal class library types should not be accessible from the EXE assembly, but somehow I get my instances created.

How does it work?

Cotten answered 26/11, 2014 at 13:38 Comment(1)
Internal classes ARE accessible by reflection.Mohun
A
10

MEF typically uses reflection to discover parts and instantiate them. Reflection is not limited by internal or even private visibility.

Anachronistic answered 26/11, 2014 at 13:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.