@@ -124,23 +124,38 @@ internal class EndpointDefaults
124
124
// }
125
125
internal class EndpointConfig
126
126
{
127
+ private IConfigurationSection _configSection ;
128
+ private ConfigSectionClone _configSectionClone ;
129
+
127
130
public string Name { get ; set ; }
128
131
public string Url { get ; set ; }
129
132
public HttpProtocols ? Protocols { get ; set ; }
130
-
131
- // REVIEW: ConfigSection doesn't seem comparable. If someone changes a custom key and consumes it in
132
- // their Action<EndpointConfiguration>, we won't rebind.
133
- public IConfigurationSection ConfigSection { get ; set ; }
134
133
public CertificateConfig Certificate { get ; set ; }
135
134
135
+ // Compare config sections because it's accessible to app developers via an Action<EndpointConfiguration> callback.
136
+ // We cannot rely entirely on comparing config sections for equality, because KestrelConfigurationLoader.Reload() sets
137
+ // EndpointConfig properties to their default values. If a default value changes, the properties would no longer be equal,
138
+ // but the config sections could still be equal.
139
+ public IConfigurationSection ConfigSection
140
+ {
141
+ get => _configSection ;
142
+ set
143
+ {
144
+ _configSection = value ;
145
+ // The IConfigrationSection will mutate, so we need to take a snapshot to compare against later and check for changes.
146
+ _configSectionClone = new ConfigSectionClone ( value ) ;
147
+ }
148
+ }
149
+
136
150
public override bool Equals ( object obj ) =>
137
151
obj is EndpointConfig other &&
138
152
Name == other . Name &&
139
153
Url == other . Url &&
140
154
( Protocols ?? ListenOptions . DefaultHttpProtocols ) == ( other . Protocols ?? ListenOptions . DefaultHttpProtocols ) &&
141
- Certificate == other . Certificate ;
155
+ Certificate == other . Certificate &&
156
+ _configSectionClone == other . _configSectionClone ;
142
157
143
- public override int GetHashCode ( ) => HashCode . Combine ( Name , Url , Protocols ?? ListenOptions . DefaultHttpProtocols , Certificate ) ;
158
+ public override int GetHashCode ( ) => HashCode . Combine ( Name , Url , Protocols ?? ListenOptions . DefaultHttpProtocols , Certificate , _configSectionClone ) ;
144
159
145
160
public static bool operator == ( EndpointConfig lhs , EndpointConfig rhs ) => lhs is null ? rhs is null : lhs . Equals ( rhs ) ;
146
161
public static bool operator != ( EndpointConfig lhs , EndpointConfig rhs ) => ! ( lhs == rhs ) ;
0 commit comments