views:

8

answers:

0

Hi I am having some dificulties regarding my application design. I have a module that is resposible for creating scopedregionmanagers based on the outside xaml in which i define regions. When I inject those outside xaml-s i create scoped regionmanagers and then i register them in the container:

detailregionmanager = regionmanager1.Regions("MainRegion").Add(model.View, "ScopeRegion", True) _container.RegisterInstance(Of IRegionManager)("ScopeRegionManager", detailregionmanager)

Then in other modules which inject their views in scope regions I resolve scopedregionmanager:

Dim regionmanager As IRegionManager regionmanager = _container.Resolve(Of IRegionManager)("ScopeRegionManager“)

Is this OK? Problem is when I want to dispose existing scopedregionmanagers and everything in the MainRegion, I dont know how to do it. I want to dispose all injected views, regionmanagers, and show Starting view in the MainRegion where user choses another ''application''. I try this:

_regionmanager.Regions("MainRegion").Remove(_regionmanager.Regions("MainRegion").Views(1)) For Each regionmanagerr As IRegionManager In _container.ResolveAll(Of IRegionManager)() If regionmanagerr Is _regionmanager Then Else For Each region As IRegion In regionmanagerr.Regions For Each view As Object In New List(Of Object)(region.Views) region.Remove(view) Next view Next _container.Teardown(regionmanagerr) End If Next

Views(0) is the starting view where user choses applications, and the selected application loads into Views(1) scopedregion so I only want to dispose Views(1). Every ''application'' loads its specific xaml-s that define regions and according to them specific views are injected into that regions. When another application is loaded (or the same application second time) i get the error in the line:

Object reference not set to an instance of an object. detailregionmanager = regionmanager1.Regions("MainRegion").Add(model.View, "ScopeRegion", True)

Probabaly becose that scopedregionmanager is already in the container. Please what am I doing wrong? Should I use childcontainer and register all instances in it and at the end dispose that childcontainer?