I've been trying to write a WPF application using PRISM and MEF and I've been able to get the Shell up and running. I want to be able to load Modules on demand so I need an instance of IModuleManager in the Shell. However, when I try to import it, the
application breaks. Here is the relevant code:
Bootstrapper:
No exports were found that match the constraint:
ContractNameShell
RequiredTypeIdentityShell
If I remove the [Import] attribute for the IModuleManager, everything works fine. Is there something I need to do to export IModuleManager?
Bootstrapper:
public class Bootstrapper : MefBootstrapper { protected override DependencyObject CreateShell() { return this.Container.GetExportedValue<Shell>(); } protected override void InitializeShell() { base.InitializeShell(); Application.Current.MainWindow = (Shell)this.Shell; Application.Current.MainWindow.Show(); } protected override void ConfigureAggregateCatalog() { base.ConfigureAggregateCatalog(); // Add this assembly to export ModuleTracker this.AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Bootstrapper).Assembly)); DirectoryModuleCatalog moduleCatalog = new DirectoryModuleCatalog(); moduleCatalog.ModulePath = @".\Modules"; moduleCatalog.Load(); foreach (ModuleInfo moduleInfo in moduleCatalog.Modules) { this.ModuleCatalog.AddModule(moduleInfo); } DirectoryCatalog catalog = new DirectoryCatalog(@".\Modules"); this.AggregateCatalog.Catalogs.Add(catalog); base.ConfigureAggregateCatalog(); } protected override void ConfigureContainer() { //Export the Container so that it can be injected if needed. this.Container.ComposeExportedValue(Container); //Export the Module Catalog so that it can be injected if needed. this.Container.ComposeExportedValue(ModuleCatalog); base.ConfigureContainer(); } protected override IModuleCatalog CreateModuleCatalog() { return new ConfigurationModuleCatalog(); } }Shell:
[Export(typeof(Shell))] public partial class Shell : Window, IPartImportsSatisfiedNotification { [Import(AllowRecomposition = false)] private IModuleManager moduleManager; public Shell() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { } public void OnImportsSatisfied() { } }The exception I'm getting is:
No exports were found that match the constraint:
ContractNameShell
RequiredTypeIdentityShell
If I remove the [Import] attribute for the IModuleManager, everything works fine. Is there something I need to do to export IModuleManager?