CompositionInitializer Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Provides static access to methods for parts to satisfy imports.

Inheritance Hierarchy


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


Public NotInheritable Class CompositionInitializer
public static class CompositionInitializer


  Name Description
Public methodStatic member SatisfyImports(ComposablePart) Fills the imports of the specified part.
Public methodStatic member SatisfyImports(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.

Partial Public Class MainPage
    Inherits UserControl

    Public Property addIn As MyAddIn

    Public Sub New()
        TextBox1.Text = addIn.getTheData()

    End Sub

End Class

Public Class MyAddIn

    Public Property subOne As MySubOne

    Public Property subTwo As MySubTwo

    Public Function getTheData() As String
        '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 + " " +
    End Function

End Class

Public Class MySubOne
    Public data = "Sub One String!"
End Class

Public Class MySubTwo
    Public data = "Sub Two String!"
End Class
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!";

Version Information


Supported in: 5, 4


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

Thread Safety

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