CompositionInitializer is missing in MEF 4.5. What can I use instead?

I cannot find System.ComponentModel.Composition.Initialization.dll in .NET 4.5 (which contains the declaration of the CompositionInitializer class). Has this assembly been removed from MEF in .NET 4.5? How can I now compose parts of an application marked with the [Export] and [Import] attributes?

Suppose I have this view:

    internal partial class StartWindow : Window
    {
        public StartWindow()
        {
            InitializeComponent();
            DataContext = ViewModel;
        }

        [Import]
        public IStartWindowViewModel ViewModel { get; set; }
    }

      

and the corresponding ViewModel:

    [Export]
    internal class StartWindowViewModel : IStartWindowViewModel
    {
        public IEnumerable<Customer> Customers { get; set; }
    }

      

What should I add to my wrapper (or anywhere else) to lay out these parts?

+3


source to share


2 answers


CompositionInitializer

and similar classes exist in Silverlight, but not in the full .NET Framework. The MEF team purposefully decided to keep them as they felt they weren't the right fit.

The logic was that construct injection should be used instead.



However, the logic used in Silverlight to use the class is the same in WPF. I wrote about this in .NET 4 and included an implementation that works for the complete framework.

+5


source


you lost composition init, fe

    _container = new CompositionContainer(catalog);

    //Fill the imports of this object
    try
    {
        this._container.ComposeParts(this);
    }
    catch (CompositionException compositionException)
    {
        Console.WriteLine(compositionException.ToString());
    }

      



msdn

+1


source







All Articles