// Create a new composition container var container = new CompositionContainer(); // Add some parts to the container container.AddPart(new Foo()); container.AddPart(new Bar()); // Compose the parts together container.Compose();
// Create a new composition container and catalog var catalog = new AssemblyCatalog(Assembly.GetExecutingAssembly()); var container = new CompositionContainer(catalog); // Compose the parts together container.Compose();In this example, we create a new container and catalog. We pass in the executing assembly to the `AssemblyCatalog` constructor to find all the parts in the current application. We then pass the catalog to the container constructor and call the `Compose` method to resolve any dependencies and create an object graph of the initialized components. Package/library: System.ComponentModel.Composition (part of .NET Framework)