У меня следующая настройка:
Я использую MEF как структуру DI для подключения различные части моего приложения.
У меня есть 2 региона:
Одна (левая) заполнена список (например, клиенты)
Один (правый) заполнен представление, содержащее tabcontrol с район, который я заселил (по к какому клиенту выбран) с другое представление, содержащее элемент управления вкладкой с областью.
Результат справа:
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