I have the following setup:
- An Silverlight app split across xaps/modules
I use MEF as DI framework to connect various parts of my application.
I have 2 regions:
One (the left one) is populated with a list view (e.g. customers)
One (the right one) is populated with a view containing a tabcontrol with a region which I populated (according to which customer is selected) with another view containin a tab control with a region.
The right side result:
To populate the first level tabcontrol I am listening to the "customer changed event" - (this works great) and when I get receive the event I populate the First Level tab area with Views:
Dim lReg As IRegion = Me.mRegionManager.Regions("FirstLevelTabReqion")
Dim lViewID As String = CommonDefinitions.Constants.BuildFirstLevelViewName(lUniqueID)
Dim lFirstLevelView FirstLevelView = TryCast(lReg.GetView(lRqViewID), FirstLevelView)
If lFirstLevelView Is Nothing Then
lFirstLevelView = New FirstLevelView()
Dim lRegMan1 As IRegionManager = lReg.Add(lFirstLevelView, lViewID, True)
lFirstLevelView.SetRegionManager(lRegMan1)
...
End If
Note: When creating the FirstLevelView I have to throw in a CompositionInitializer.SatisfyImports
call to make sure the FirstLevelView resolves its ViewModel reference.
To get an instance of the EventsAggregator in the SecondLevel ViewModel I use:
<ImportingConstructor()>
Public Sub New(ByVal iEvAggregator As IEventAggregator)
EventAggregator = iEvAggregator
EventAggregator.GetEvent(Of DoStuffSecondLevel).Subscribe(AddressOf OnDoStuffSecondLevel, True)
End Sub
My problem is that the EventAggregator instance I get in the second level view model is different from the EventAggregator instance in the first level so if I publish DoStuffSecondLevel on the first level it will not be caught in the second level.
Why do I get 2 different instances of the EventAggregator?
What can I do to share the same instance of the EventAggregator across the application?
Thanks in advance
ComponentInitializer.SatisfyImports(this);
I used theComponentInitializer.SatisfyImports(...)
so that I can new() my other ViewModels (so I don't have to reset their states manually), which led me to use the SatisfyImports so I can get my services, mainly the EventAggregator. – michael