Feb 4, 2011 at 12:47 PM
Edited Feb 4, 2011 at 1:07 PM
I am a bit stuck with this. I have introduced a new paremeter in a ctor of my NavigationViewModel. Now Prism can't resolve the parameter any more. And I get this error message:
Microsoft JScript runtime error: Unhandled Error in Silverlight Application An exception occurred while initializing module 'NavigationModule'. - The exception message was: Activation error occured while trying to get instance of
type NavigationModule, key '' Check the InnerException property of the exception for more information. If the exception occurred while creating an object in a DI container, you can exception.GetRootException() to help
locate the root cause of the problem. at Microsoft.Practices.Prism.Modularity.ModuleInitializer.HandleModuleInitializationError(ModuleInfo moduleInfo, String assemblyName, Exception exception) at Microsoft.Practices.Prism.Modularity.ModuleInitializer.Initialize(ModuleInfo
moduleInfo) at Microsoft.Practices.Prism.Modularity.ModuleManager.LoadModulesThatAreReadyForLoad()
My navigationModule has the ctor like this:
public NavigationModule(IUnityContainer container, IRegionManager regionManager)
_container = container;
_regionManager = regionManager;
//Atempt to register DomainClient, which doesn't seem to work.
_regionManager.RegisterViewWithRegion(Constants.NavRegion, () => _container.Resolve<NavigationView>());
_regionManager.RegisterViewWithRegion(Constants.ToolbarRegion, () => _container.Resolve<ToolbarView>());
Navigation View Model owns by Navigation View looks simply like this:
public NavigationViewModel(DomainClient client)
_context = new SCMDomainContext(client);
I suspect the problem is that DomainClient is an abstract class from RIA Services and the IoC can't create an instance of this abstract class, hence the error correct?
In this case, I would be happy if I could force it to ignore the ctor with the abstract DomainClient parameter, and rather try to resolve a different ctor with the non-abstract SCMDomainContext like this:
public NavigationViewModel(SCMDomainContext context)
_context = context;
1) How would I do that in Unity?
2) Problem with MEF is that it needs an export attribute, but even the non-abstract SCMDomainContext is auto generated code by RIA services. I couldn't just go there and add an [Export] attribute on top of it? And how would I do this with MEF?
I tried to use this to select the correct ctor for injection, but it failed.
Besides the Injectedmember is obsolete anyway, I wondr how I have to do it nowadays. :)
I got frustrated and removed the ctor with the abstract class injection temporarily all together so that only one ctor with SCMDomainContext can be injected in. But it can't even resolve the non-abstract SCMDomainContext, which is auto generated code by
Your help on this is highly appreciated,