* Forgotten v12 obsoletions * V13 obsoletions * Remove LegacyStaticServiceProvider and fix using statements of StaticServiceProvider * Remove obsolete ctors for v13 * More v13 obsoletions * UmbracoMapper obsoletion * UmbracoPipelineFilter obsoletion --------- Co-authored-by: nikolajlauridsen <nikolajlauridsen@protonmail.ch>
49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.Options;
|
|
using Umbraco.Cms.Core.Configuration.Models;
|
|
using Umbraco.Extensions;
|
|
|
|
namespace Umbraco.Cms.Core.Configuration;
|
|
|
|
/// <summary>
|
|
/// Configures the <see cref="ConnectionStrings" /> named option.
|
|
/// </summary>
|
|
public class ConfigureConnectionStrings : IConfigureNamedOptions<ConnectionStrings>
|
|
{
|
|
private readonly IConfiguration _configuration;
|
|
|
|
/// <summary>
|
|
/// Initializes a new instance of the <see cref="ConfigureConnectionStrings" /> class.
|
|
/// </summary>
|
|
/// <param name="configuration">The configuration.</param>
|
|
public ConfigureConnectionStrings(IConfiguration configuration)
|
|
=> _configuration = configuration;
|
|
|
|
/// <inheritdoc />
|
|
public void Configure(ConnectionStrings options) => Configure(Options.DefaultName, options);
|
|
|
|
/// <inheritdoc />
|
|
public void Configure(string? name, ConnectionStrings options)
|
|
{
|
|
if (name is null)
|
|
{
|
|
throw new InvalidOperationException("The name of the option instance is required.");
|
|
}
|
|
|
|
// Default to using UmbracoConnectionName
|
|
if (name == Options.DefaultName)
|
|
{
|
|
name = Constants.System.UmbracoConnectionName;
|
|
}
|
|
|
|
if (options.IsConnectionStringConfigured())
|
|
{
|
|
return;
|
|
}
|
|
|
|
options.ConnectionString = _configuration.GetUmbracoConnectionString(name, out string? providerName);
|
|
options.ProviderName = providerName ??
|
|
ConnectionStrings.DefaultProviderName;
|
|
}
|
|
}
|