MefDumper is a command-line tool (based on "CLR MD") that aims to dump MEF CompositionContainer objects in order to create directed graphs that represent the dependencies among the various parts within the container. The tool supports the following scenarios.
In this scenario, an AssemblyCatalog is created for all the provided assemblies who in turn are passed to an AggregateCatalog. It's important to provide all the related assemblies that take part in the composition else there will be many orphan parts in the resulting digraph. Exports and imports are identified by their corresponsing attributes, ExportAttribute and ImportAttribute.
Usage:
MefDumper -a test.dll[;test2.dll;...;testN.dll]
In this scenario, MefDumper extracts additional information compared to the previous scenario. These are:
- Parts that have been instantiated (green boxes)
- Objects that were put into the container directly, via APIs like ComposeExportedValue (see Limitations)
- The type names of custom ExportProviders
Usage:
MefDumper -d test.dmp
In this scenario, the same pieces of information are extracted as in the previous scenario.
Usage:
MefDumper -pid <processId>
-
For extensibility reasons, CompositionContainer supports the concept of custom ExportProviders whose structure unfortunately can't be predicted. This approach is typically used in advanced scenarios, like when Visual Studio uses its own MEF implementation.
-
There are some APis like ComposeExportedValue that allow you to put object instances into containers directly. When dumping managed assemblies such (hidden) exports can't be recognized. In the other scenarios however, you'll get full support for these objects.
-
There are some APis like GetExportedValue that allow you to retrieve objects from containers directly. Such (hidden) dependencies can't be recognized, unless you explicitly tell MEF about them. Given the following "hidden" dependency:
ComponentA: var instanceOfB = CompositionContainer.GetExportedValue<IComponentB>("ContractOfComponentB");
One can add the following field to ComponentA to let MEF know about the dependency:
[Import("ContractOfComponentB", AllowDefault = true)] private Lazy<IComponentB> _componentB;
Graph drawing and visualization is an extremely complex topic. (See this handbook for a glimpse). That's why MefDumper creates Directed Graph Markup Language (DGML) files so that it can utilize the existing tooling out there.
I'd recommend using the DGML editor that ships with Visual Studio 2017+. (You might have to install it from the Visual Studio installer "Individual components" tab.)
If you like the project please consider a small donation via