You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+5Lines changed: 5 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,6 +39,11 @@ linked here:
39
39
* Character Mapping - Some config builders have had an internal mapping of characters that might exist in keys in the config file but are illegal in keys at the
40
40
source. As more scenarios come to light and individual prefrences are not always unanimous, V3 instead adds the [`charMap`](docs/KeyValueConfigBuilders.md#charmap) attribute to allow this character
41
41
mapping to work with all **KeyValueConfigBuilders** and to be handled in an easily configurable manner.
42
+
*`ConnectionStringsSectionHandler2` - A new section handler for the `<connectionStrings>` section has been included in the base package. This new handler will
43
+
allow updating of both the 'connectionString' attribute as well as the 'providerName' attribute. It does require the builders and source of config data to be
44
+
aware of this new ability though. The default section handler for the `<connectionStrings>` section has not been updated and remains as it was in previous
45
+
versions, so apps wishing to take advantage of the new handler will have to wire it up in their config. More details can be found in the
* Azure App Configuration Support - There is a [new builder](docs/KeyValueConfigBuilders.md#azureappconfigurationbuilder) for drawing values from the new Azure App Configuration service.
One thing to note is that the mechanism for associating a key/value lookup with a specific attribute of connection string entries
115
+
is a simple post-fix to the key. This makes this feature incompatible with versioned keys in Azure Key Vault. Most other cases should
116
+
just work as they did before, with a little extra magic cleanliness when you start using this feature.
117
+
118
+
An example of this new behavior from `ConnectionStringsSectionHandler2` can be seen in the [SampleConsoleApp](samples/SampleConsoleApp/App.config#L37-L46).
119
+
Or in the [test project](https://github.com/aspnet/MicrosoftConfigurationBuilders/blob/main/test/Microsoft.Configuration.ConfigurationBuilders.Test/ConnectionStringsSectionHandler2Tests.cs).
120
+
The [SampleWebApp](samples/SampleWebApp/Web.config#L38-L41) does not use the new section handler, but it does include some notes about how
121
+
it's resulting connection string collection would look different if it did.
/// Updates an existing connection string attribute in the assigned <see cref="SectionHandler{T}.ConfigSection"/> with a new name and a new value. The old
229
+
/// connection string setting can be located using the <paramref name="oldItem"/> parameter. If an old connection string is not found, a new connection
230
+
/// string should be inserted.
231
+
/// </summary>
232
+
/// <param name="newKey">The updated key name for the connection string. May be post-fixed with attribute tag.</param>
233
+
/// <param name="newValue">The updated value for the connection string.</param>
234
+
/// <param name="oldKey">The old key name for the connection string, or null. May be post-fixed with attribute tag.</param>
235
+
/// <param name="oldItem">A reference to the old <see cref="ConnectionStringSettings"/> object obtained by <see cref="KeysValuesAndState"/>, or null.</param>
// Make sure there are no entries using the old or new name other than this one
246
+
ConfigSection.ConnectionStrings.Remove(oldKey);
247
+
ConfigSection.ConnectionStrings.Remove(newKey);
248
+
249
+
// Update values and re-add to the collection (no state means 'Greedy' mode where we do want to update)
250
+
if(state==null||state.UpdateName)
251
+
cs.Name=newKey;
252
+
if(tag==providerNameTag)
253
+
cs.ProviderName=newValue;
254
+
else
255
+
cs.ConnectionString=newValue;
256
+
ConfigSection.ConnectionStrings.Add(cs);
257
+
}
258
+
259
+
/// <summary>
260
+
/// Gets an <see cref="IEnumerable{T}"/> for iterating over the key/value pairs contained in the assigned <see cref="SectionHandler{T}.ConfigSection"/>. />
261
+
/// </summary>
262
+
/// <returns>An enumerator over tuples where the values of the tuple are the existing name for each connection string, the value of
263
+
/// the connection string or the value of the provider name, and a reference to the <see cref="ConnectionStringSettings"/> object itself
264
+
/// which will be returned to us as a reference state object when updating the config record.</returns>
0 commit comments