It looks like I've found a workaround for this problem, and I'm not quite sure that it would be THE solution. So any reactions would still be very much welcome!
I've given up the principle that the ViewModel would be instantiated from the View.xaml. That brings me to the next "least objectable alternative" of initializing it from the View's code behind. This is the new command for that:
<Import(AllowRecomposition:=False)> Public Property ViewModel As StartViewModel
The ViewModel has to be reworked, so that it can be discovered by MEF. It needs an <Export> attribute and it can no longer inherit from mt Base_ViewModel. Instead, I use an ImportingConstructor to inject the necessary objects:
<Export()> Public Class StartViewModel
<ImportingConstructor()> Sub New(EA As IEventAggregator, MM As IModuleManager)
If Not IsNothing(EA) Then
Locale_EventAggregator = EA
End If
If Not IsNothing(MM) Then
Locale_ModuleManager = MM
End If
...
...
End Sub
But that lead to a new problem: the IModuleManager and the IEventAggregator appeared to be NOT the same instances as the ones created for the other modules. So in my bootstrapper I force the container to be the same container for both Prism and MEF with this command:
Protected Overrides Function CreateContainer() As CompositionContainer
Dim Local_Container = MyBase.CreateContainer()
CompositionHost.Initialize(Local_Container)
Return Local_Container
End Function
As I said: I'm not completely certain of what I have done here, and comments or improvements to this solution would be highly appreciated!
ModuleManagerMEFimport
Regards,
Peter
Please mark as "answer" if this post helped you.
Peter Klein
Participant
1001 Points
322 Posts
RE: ModuleManager blues ---->>> SOLVED !! Any comments/improvement suggestions?
Jan 18, 2012 12:17 PM | LINK
Hi All,
In addition to this: from the Codeplex Practices&Patterns group I did receive confirmation that this behviour of the IModuleManager is a reproducable error: see http://compositewpf.codeplex.com/discussions/286333#post727221
It looks like I've found a workaround for this problem, and I'm not quite sure that it would be THE solution. So any reactions would still be very much welcome!
I've given up the principle that the ViewModel would be instantiated from the View.xaml. That brings me to the next "least objectable alternative" of initializing it from the View's code behind. This is the new command for that:
And of course the related xaml code is skipped:
<UserControl.DataContext> <vm:StartViewModel/> </UserControl.DataContext>The ViewModel has to be reworked, so that it can be discovered by MEF. It needs an <Export> attribute and it can no longer inherit from mt Base_ViewModel. Instead, I use an ImportingConstructor to inject the necessary objects:
<Export()> Public Class StartViewModel <ImportingConstructor()> Sub New(EA As IEventAggregator, MM As IModuleManager) If Not IsNothing(EA) Then Locale_EventAggregator = EA End If If Not IsNothing(MM) Then Locale_ModuleManager = MM End If ... ... End SubBut that lead to a new problem: the IModuleManager and the IEventAggregator appeared to be NOT the same instances as the ones created for the other modules. So in my bootstrapper I force the container to be the same container for both Prism and MEF with this command:
Protected Overrides Function CreateContainer() As CompositionContainer Dim Local_Container = MyBase.CreateContainer() CompositionHost.Initialize(Local_Container) Return Local_Container End FunctionAs I said: I'm not completely certain of what I have done here, and comments or improvements to this solution would be highly appreciated!
ModuleManager MEF import
Peter
Please mark as "answer" if this post helped you.