using System.Data.Common; using Microsoft.Extensions.Configuration; namespace Kyoo.Database { /// /// A class that regroup extensions used by some asp-net related parts of the app. /// public static class Extensions { /// /// Get a connection string from the Configuration's section "Database" /// /// The IConfiguration instance to use. /// The database's name. /// A parsed connection string public static string GetDatabaseConnection(this IConfiguration config, string database) { DbConnectionStringBuilder builder = new(); IConfigurationSection section = config.GetSection("database:configurations").GetSection(database); foreach (IConfigurationSection child in section.GetChildren()) builder[child.Key] = child.Value; return builder.ConnectionString; } /// /// Get the name of the selected database. /// /// The IConfiguration instance to use. /// The name of the selected database. public static string GetSelectedDatabase(this IConfiguration config) { return config.GetValue("database:enabled"); } } }