@@ -5,15 +5,15 @@ namespace Microsoft.AspNetCore.Components.Sections;
55
66internal sealed class SectionRegistry
77{
8- private readonly Dictionary < string , ISectionContentSubscriber > _subscribersByName = new ( ) ;
9- private readonly Dictionary < string , List < ISectionContentProvider > > _providersByName = new ( ) ;
8+ private readonly Dictionary < object , ISectionContentSubscriber > _subscribersBySectionId = new ( ) ;
9+ private readonly Dictionary < object , List < ISectionContentProvider > > _providersBySectionId = new ( ) ;
1010
11- public void AddProvider ( string name , ISectionContentProvider provider , bool isDefaultProvider )
11+ public void AddProvider ( object sectionId , ISectionContentProvider provider , bool isDefaultProvider )
1212 {
13- if ( ! _providersByName . TryGetValue ( name , out var providers ) )
13+ if ( ! _providersBySectionId . TryGetValue ( sectionId , out var providers ) )
1414 {
1515 providers = new ( ) ;
16- _providersByName . Add ( name , providers ) ;
16+ _providersBySectionId . Add ( sectionId , providers ) ;
1717 }
1818
1919 if ( isDefaultProvider )
@@ -26,18 +26,18 @@ public void AddProvider(string name, ISectionContentProvider provider, bool isDe
2626 }
2727 }
2828
29- public void RemoveProvider ( string name , ISectionContentProvider provider )
29+ public void RemoveProvider ( object sectionId , ISectionContentProvider provider )
3030 {
31- if ( ! _providersByName . TryGetValue ( name , out var providers ) )
31+ if ( ! _providersBySectionId . TryGetValue ( sectionId , out var providers ) )
3232 {
33- throw new InvalidOperationException ( $ "There are no content providers with the name ' { name } '.") ;
33+ throw new InvalidOperationException ( $ "There are no content providers with the given section ID ' { sectionId } '.") ;
3434 }
3535
3636 var index = providers . LastIndexOf ( provider ) ;
3737
3838 if ( index < 0 )
3939 {
40- throw new InvalidOperationException ( $ "The provider was not found in the providers list of name ' { name } '.") ;
40+ throw new InvalidOperationException ( $ "The provider was not found in the providers list of the given section ID ' { sectionId } '.") ;
4141 }
4242
4343 providers . RemoveAt ( index ) ;
@@ -47,44 +47,44 @@ public void RemoveProvider(string name, ISectionContentProvider provider)
4747 // We just removed the most recently added provider, meaning we need to change
4848 // the current content to that of second most recently added provider.
4949 var content = GetCurrentProviderContentOrDefault ( providers ) ;
50- NotifyContentChangedForSubscriber ( name , content ) ;
50+ NotifyContentChangedForSubscriber ( sectionId , content ) ;
5151 }
5252 }
5353
54- public void Subscribe ( string name , ISectionContentSubscriber subscriber )
54+ public void Subscribe ( object sectionId , ISectionContentSubscriber subscriber )
5555 {
56- if ( _subscribersByName . ContainsKey ( name ) )
56+ if ( _subscribersBySectionId . ContainsKey ( sectionId ) )
5757 {
58- throw new InvalidOperationException ( $ "There is already a subscriber to the content ' { name } '.") ;
58+ throw new InvalidOperationException ( $ "There is already a subscriber to the content with the given section ID ' { sectionId } '.") ;
5959 }
6060
6161 // Notify the new subscriber with any existing content.
62- var content = GetCurrentProviderContentOrDefault ( name ) ;
62+ var content = GetCurrentProviderContentOrDefault ( sectionId ) ;
6363 subscriber . ContentChanged ( content ) ;
6464
65- _subscribersByName . Add ( name , subscriber ) ;
65+ _subscribersBySectionId . Add ( sectionId , subscriber ) ;
6666 }
6767
68- public void Unsubscribe ( string name )
68+ public void Unsubscribe ( object sectionId )
6969 {
70- if ( ! _subscribersByName . Remove ( name ) )
70+ if ( ! _subscribersBySectionId . Remove ( sectionId ) )
7171 {
72- throw new InvalidOperationException ( $ "The subscriber with name ' { name } ' is already unsubscribed.") ;
72+ throw new InvalidOperationException ( $ "The subscriber with the given section ID ' { sectionId } ' is already unsubscribed.") ;
7373 }
7474 }
7575
76- public void NotifyContentChanged ( string name , ISectionContentProvider provider )
76+ public void NotifyContentChanged ( object sectionId , ISectionContentProvider provider )
7777 {
78- if ( ! _providersByName . TryGetValue ( name , out var providers ) )
78+ if ( ! _providersBySectionId . TryGetValue ( sectionId , out var providers ) )
7979 {
80- throw new InvalidOperationException ( $ "There are no content providers with the name ' { name } '.") ;
80+ throw new InvalidOperationException ( $ "There are no content providers with the given section ID ' { sectionId } '.") ;
8181 }
8282
8383 // We only notify content changed for subscribers when the content of the
8484 // most recently added provider changes.
8585 if ( providers . Count != 0 && providers [ ^ 1 ] == provider )
8686 {
87- NotifyContentChangedForSubscriber ( name , provider . Content ) ;
87+ NotifyContentChangedForSubscriber ( sectionId , provider . Content ) ;
8888 }
8989 }
9090
@@ -93,14 +93,14 @@ public void NotifyContentChanged(string name, ISectionContentProvider provider)
9393 ? providers [ ^ 1 ] . Content
9494 : null ;
9595
96- private RenderFragment ? GetCurrentProviderContentOrDefault ( string name )
97- => _providersByName . TryGetValue ( name , out var existingList )
96+ private RenderFragment ? GetCurrentProviderContentOrDefault ( object sectionId )
97+ => _providersBySectionId . TryGetValue ( sectionId , out var existingList )
9898 ? GetCurrentProviderContentOrDefault ( existingList )
9999 : null ;
100100
101- private void NotifyContentChangedForSubscriber ( string name , RenderFragment ? content )
101+ private void NotifyContentChangedForSubscriber ( object sectionId , RenderFragment ? content )
102102 {
103- if ( _subscribersByName . TryGetValue ( name , out var subscriber ) )
103+ if ( _subscribersBySectionId . TryGetValue ( sectionId , out var subscriber ) )
104104 {
105105 subscriber . ContentChanged ( content ) ;
106106 }
0 commit comments