How to read MEF metadata in a DLL plugin without copying the entire DLL into memory?

Background:

I'm interested in using MEF to provide plug-in architecture in a WinForm application using C # with .NET 4.0, but I don't know what came of it.

Firstly: I didn’t work at all with creating DLLs in C # yet, and I’m a bit vague in the concept of DLL collections and load DLLs as usual (which means everything at once or as parts, as needed)

Purpose:

The program will be the basis for managing hardware and will consist of the main WinForm GUI, which is a common environment with the main toolbars, menus, etc., but without the massive contents of the graphical interface. (Think: MDI Parent, but not really).

Plugins provide all the controls for a particular machine. Each of the many possible plugins will contain potentially 30-50 large UserControls, each of which contains many dozens of WinForm controls and a lot of support code that make up various machine control panels.

This means that the main program is an easy general structure, and plugins contain the main part of the controls and functionality of the graphical interface that will be displayed in the main user interface of the program, including many icons, images and other resources. This will make the DLL plugins potentially quite large.

, , , , , .

, , , , , .

:

MEF, DLL, , DLL , ?

, DLL , , DLL MEF?

, DirectoryCatalog AggregateCatalog MEF DLL .

DLL () , ( )?

, , , , . MEF, DLL . !

+5
1

MEF, DLL , DLL , ?

, DLL . MEF. DirectoryCatalog ( AssemblyCatalog), Assembly.Load. MEF, .NET Framework. . Process Explorer, , . , , .

, DLL , , DLL MEF?

.

- , CompositionContainer AppDomain . AppDomain. AppDomain. , , . , , .

- Mono.Cecil. , . MEF Export Metadata :

public static bool IncludesTypeWithSpecificExportMetadata<T>(string assemblyPath, string name, T value)
    {
        AssemblyDefinition assemblyDefinition = AssemblyDefinition.ReadAssembly(assemblyPath);

        bool typeWasFound = false;          

        foreach (TypeDefinition typeDefinition in assemblyDefinition.MainModule.GetTypes())
        {
            foreach (CustomAttribute customAttribute in typeDefinition.CustomAttributes)
            {
                if (customAttribute.AttributeType.FullName == typeof(ExportMetadataAttribute).FullName)
                {
                    string actualName = (string)customAttribute.ConstructorArguments[0].Value;
                    T actualValue = (T)((CustomAttributeArgument)customAttribute.ConstructorArguments[1].Value).Value;
                    if (actualName.Equals(name) && actualValue.Equals(value))                        
                    {
                        typeWasFound = true;                       
                    }
                }
            }
        }

        return typeWasFound;
    }

/, Mono.Cecil , ExportMetadataAttribute /.

, DirectoryCatalog AggregateCatalog MEF DLL .

True.

DLL (), , ( )?

. "Essential.NET Volume 1" Don Box "# CLR" .

, , , , . MEF, DLL . !

, , , / -. Suzanne Cook.

- . ? , . .

, Microsoft Smart Client Software Factory. , , . , , , , .

+5

All Articles