Skip to content

Platform specific: MEF aka System.Composition

Ioan Crisan edited this page Oct 12, 2017 · 3 revisions

MEF implementation of the composition infrastructure

The implementation complexity is hidden under the Kephas.Composition.Mef namespace, in the assembly with the same name.

The MefCompositionContainerBuilder

This builder class is used to configure the composition container and add it to the ambient services. It extends the CompositionContainerBuilderBase from the core, providing MEF specific functionality.

Remarks: this class is normally not used as such, but through the AmbientServicesBuilder extension methods (see below).

The MefAmbientServicesBuilderExtensions

This static class provides convenience methods for initializing the composition container in the ambient services.

Warning: before initializing the composition container, the log manager and the application runtime must be set into the ambient services, otherwise the respective Null services will be used, which do not do anything meaningful.

Example

    var ambientServicesBuilder = await 
        new AmbientServicesBuilder()
            .WithNLogManager()
            .WithNet45AppRuntime(n => n.Name.ToLower().StartsWith("kephas.") || n.Name.ToLower().StartsWith("myapp."))
            .WithMefCompositionContainerAsync()
            .PreserveThreadContext();

Clone this wiki locally