@@ -9,9 +9,9 @@ public class RegionManager : IRegionManager
99 {
1010 private readonly ConcurrentDictionary < string , IRegion > _regions = [ ] ;
1111 private readonly IServiceProvider _serviceProvider ;
12- private readonly ConcurrentStack < NavigationContext > _buffer = [ ] ;
13- private readonly ConcurrentSet < IObserver < NavigationContext > > _navigationObservers = new ( ) ;
14- private readonly ConcurrentSet < IObserver < IRegion > > _regionsObservers = new ( ) ;
12+ private readonly ConcurrentDictionary < string , ConcurrentStack < NavigationContext > > _buffer = [ ] ;
13+ private readonly ConcurrentSet < IObserver < NavigationContext > > _navigationObservers = [ ] ;
14+ private readonly ConcurrentSet < IObserver < IRegion > > _regionsObservers = [ ] ;
1515 public RegionManager ( IServiceProvider serviceProvider )
1616 {
1717 _serviceProvider = serviceProvider ;
@@ -27,7 +27,18 @@ public void RequestNavigate(string regionName, string viewName, bool requestNew,
2727 }
2828 else
2929 {
30- _buffer . Push ( context ) ;
30+ _buffer . AddOrUpdate ( regionName ,
31+ key =>
32+ {
33+ var stack = new ConcurrentStack < NavigationContext > ( ) ;
34+ stack . Push ( context ) ;
35+ return stack ;
36+ } ,
37+ ( key , value ) =>
38+ {
39+ value . Push ( context ) ;
40+ return value ;
41+ } ) ;
3142 }
3243 }
3344
@@ -36,11 +47,14 @@ public void AddRegion(string regionName, IRegion region)
3647 if ( _regions . TryAdd ( regionName , region ) )
3748 {
3849 ToRegionsObservers ( region ) ;
39- if ( _buffer . TryPop ( out var context ) )
50+
51+ if ( _buffer . TryGetValue ( regionName , out var navigationContexts ) )
4052 {
41- region . Activate ( context ) ;
42- ToNavigationObservers ( context ) ;
43- _buffer . Clear ( ) ;
53+ if ( navigationContexts . TryPop ( out var context ) )
54+ {
55+ region . Activate ( context ) ;
56+ ToNavigationObservers ( context ) ;
57+ }
4458 }
4559 }
4660 else
0 commit comments