none
MEF Dependency Chaining RRS feed

  • Question

  • I am somewhat confused about injection chaining in MEF.
    I have the following situation

    Boostrapper (Prism MEF) Imports Program using
      Prog = Container.GetExportedValue<Program>();
    in the Bootstrapper Create Shell method override

    The App.xaml.cs is:
       Bootstrapper bs = new Bootstrapper();
       bs.Run();
       bs.Prog.Run();
    where Program is:
        [Export(typeof(Program))]
        public class Program
        {
            // Import the Data Model which is held in a Module in a separate Directory using a DataCatalog
            [Import(typeof(IDataModel))]
            IDataModel dm { get; set; }
            public void Run()
            {
    . .....
    And DataModel is:
     [Export(typeof(IDataModel))]
        class DataModel :IDataModel
        {
            //  This imports the DataStore it finds in the Module Library
            [Import(typeof(IDataStore))]     //  Does not seem to work but should (MEF chaining)
            public static IDataStore ds { get; set; }
            ...........
    DataStore is decorated with:
     [Export(typeof(IDataStore))]
        public class XMLDataStore :  IDataStore
        { .....

    Every Export is correctly in the container aand Import all work except for the import of IDataStore
    which is not satisfied.

    However if I move the Import for Datatore to the Program class just after the Import for the DataModel
    it is imported fine and I can pass it on as a parameter to a method in DataModel where it is used OK.
    What is wrong with chaining through DataModel to DataStore?

    John Meers

    Friday, November 4, 2016 6:00 PM

All replies