How to make OnDemand Prism modules work?

Apr 27, 2010 at 4:30 PM

I'm trying to load Prism modules OnDemand, but am missing something, because the MEF-exported thingies in the module seemingly are not visible to Prism.

In UnityExportProvider.GetExportsCore(...), I'm getting an ImportCardinalityMismatchException:

"No valid exports were found that match the constraint '((exportDefinition.ContractName == "UnityIntegration01.Module01.IMyOtherStuff") "... etc.

(I have set up my bootstrapper as described in http://mefcontrib.codeplex.com/Thread/View.aspx?ThreadId=210431 - and added a module catalog).

Example module:

using System;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Composite.Modularity;
using System.ComponentModel.Composition;

namespace UnityIntegration01.Module01
{
    [Export(typeof(IModule))]
    public class MyModule : IModule
    {
        [Import]
        public IMyOtherStuff Stuff { get; set; }

        #region IModule Members

        public void Initialize()
        {
            // NOP.   
        }

        #endregion
    }

    public interface IMyOtherStuff
    { }

    [Export(typeof(IMyOtherStuff))]
    public class MyOtherStuff : IMyOtherStuff
    { }
}

Any clues?

Regards,

Kasimier

Apr 27, 2010 at 6:20 PM

Temporary workaround: explicitly put the module's assembly into MEF's scope.

public MyModule(IUnityContainer container)
{
    var bootstrapper = container.Resolve<IBootstrapper>();
    var cat = new AssemblyCatalog(typeof(MyModule).Assembly);
    bootstrapper.RootCatalog.Catalogs.Add(cat);            
}

 

Can this be automated somehow? Can the MEF-contrib code be made to add the newly loaded assemblies automatically?

Regards,

Kasimier