We've run into a problem which I think may have something to do with WeakReferences being held when adding Regions to the RegionManager, and was wondering if anyone else had seen similar.
Occasionally, we are finding that our regions aren't available in the RegionManager. We have written a custom adapter for the DevExpress LayoutGroups and the Adapt method on that is not being called. We're using the UnityBootstrapper. We have two regions
to be added.
Tracing it through, the call to RegionManager.UpdateRegions() which subsequently calls WeakDelegatesManager.Raise(). There are two listeners in the listeners collection, but both of their Targets are null, and are then removed from the listeners collection.
This means that our Adapt method is never called and the regions aren't available. The xaml to configure the regions is this:
<dxdo:LayoutGroup Width="250" Orientation="Horizontal" cal:RegionManager.RegionName="PortfolioRegion" />
<dxdo:LayoutGroup cal:RegionManager.RegionName="MainRegion" />
I can force this to happen all the time by changing the following code in UnityBootstapper.cs:102 and adding a call to GC.Collect() :
this.Logger.Log(Resources.SettingTheRegionManager, Category.Debug, Priority.Low);
this.Logger.Log(Resources.UpdatingRegions, Category.Debug, Priority.Low);
I can also prevent it happening by specializing DelayedRegionCreationBehavior to keep a reference to each DelayedRegionCreationBehavior. Or I can create a Unity LifetimeManager that keeps the reference. I can't use the ContainerControlledLifetimeManager
as DelayedRegionCreationBehavior needs to be a unique instance as the TargetElements are different.
Can anyone suggest what I am doing wrong or whether it is expected behavior from Prism? Or if it isn't expected behavior, is there a fix for it?