CompositionInitializer Class

Provides static access to methods for parts to satisfy imports.


Namespace:  System.ComponentModel.Composition
Assembly:  System.ComponentModel.Composition.Initialization (in System.ComponentModel.Composition.Initialization.dll)

public static class CompositionInitializer

Public methodStatic memberSatisfyImports(ComposablePart)Fills the imports of the specified part.
Public methodStatic memberSatisfyImports(Object)Fills the imports of the specified attributed part.

This class is designed to allow parts to fill imports without the need to go through container initialization. Calls to the methods of this class are filled by using a default container loaded with all the parts found in the XAP file.

There are a few limitations on CompositionInitializer:

  • Parts passed to SatisfyImports for composition cannot have exports of their own, or the method will result in an exception.

  • Parts created by the default container to fill imports will be retained by the Managed Extensibility Framework (MEF) until the application shuts down. Long-running applications should using ExportFactory<T> to manage the life cycles of their parts.

You can replace the default container with a custom container by calling the Initialize static method.

The following code shows how to satisfy the imports for a part and get data from the part. To use this code, create a Silverlight project with a TextBox named textBox1. Add the following code to the code-behind file.

public partial class MainPage : UserControl
    public MyAddIn addIn { get; set; }

    public MainPage()
        textBox1.Text = addIn.getTheData();

public class MyAddIn
    public MySubOne subOne { get; set; }

    public MySubTwo subTwo { get; set; }

    public String getTheData()
        //This is safe, because MEF guarantees this
        //object will never be created with null references!
        //If it can't fill those imports, composition
        //will fail.
        return + " " +;


public class MySubOne
    public String data = "Sub One String!";

public class MySubTwo
    public String data = "Sub Two String!";


Supported in: 5, 4

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Community Additions