is an update for MEF that is optimized for web and Windows 8 Store apps. It is distributed as a NuGet package compatible with the .NET 4.5 Framework and
.NET for Windows Store apps.
These environments do not emphasize in-place third party extensibility, and so composition in these environments can be simplified and streamlined.
Microsoft.Composition includes a lifetime model oriented towards the 'unit of work' patterns that appear in server-side and MVVM-style applications.
Throughput under server workloads is several orders of magnitude higher than what can be achieved with CompositionContainer, and with almost zero contention.
First, install the Microsoft.Composition NuGet package
Manage NuGet Packages
dialog in Visual Studio, or from the Package Manager Console
PM> Install-Package Microsoft.Composition -Pre
This will add a number of assemblies to the project.
for Microsoft.Composition use the familiar MEF attributes, found in the
public class MessageHandler : IMessageHandler
public MessageHandler(IDatabaseConnection connection)
is created using a simple ContainerConfiguration
var configuration = new ContainerConfiguration()
using (var container = configuration.CreateContainer())
var greeter = container.GetExport<IMessageHandler>();
provides the methods
as well as the
method for plugging in container extensions.
are defined in Microsoft.Composition using
var conventions = new ConventionBuilder();
configuration methods accept conventions as parameters:
supports the same syntax and rules as
does in the full-framework version of MEF. The BCL Team Blog discusses how to
If you are familiar with MEF in the .NET Framework 4.0 and onwards, see the
for further information.