MEF detect appropriate constructor

Jul 2, 2011 at 3:32 PM

Hello,

I have some problem to undestand how create a Module with a constructor that receive parameters, for instance:

[ImportingConstructor ]

public ModuleInit(IRegionManager regionManager)

{ 

this._regionManager = regionManager;

}

 

 

When I try to get the object from the bootstrapper I receive the following error:

Code in MefBootStrapper:

this.Container.GetExportedValue<Contract.Menu.IModuleInit

>(); 

 

Error:

The composition produced a single composition error. The root cause is provided below. Review the CompositionException.Errors property for more detailed information. 1) Cannot create an instance of type 'JS.FWK.Prism.Menu.ModuleInit' because a constructor could not be selected for construction. Ensure that the type either has a default constructor, or a single constructor marked with the 'System.ComponentModel.Composition.ImportingConstructorAttribute'. Resulting in: Cannot activate part 'JS.FWK.Prism.Menu.ModuleInit'. Element: JS.FWK.Prism.Menu.ModuleInit --> JS.FWK.Prism.Menu.ModuleInit --> DirectoryCatalog (Path="D:\Jerry\Develop\00_Enviroment\99_Prism") Resulting in: Cannot get export 'JS.FWK.Prism.Menu.ModuleInit (ContractName="JS.FWK.Prism.Contract.Menu.IModuleInit")' from part 'JS.FWK.Prism.Menu.ModuleInit'. Element: JS.FWK.Prism.Menu.ModuleInit (ContractName="JS.FWK.Prism.Contract.Menu.IModuleInit") --> JS.FWK.Prism.Menu.ModuleInit --> DirectoryCatalog (Path="D:\Jerry\Develop\00_Enviroment\99_Prism")

Could someone help me?

Many thanks for you support

Jerry