| | | 1 | | using ZhEaIsNsAaBn.APPSettings; |
| | | 2 | | using ZhEaIsNsAaBn.APPSettings.Builders; |
| | | 3 | | |
| | | 4 | | // ReSharper disable once CheckNamespace |
| | | 5 | | namespace Microsoft.Extensions.Configuration; |
| | | 6 | | |
| | | 7 | | /// <summary>Adds settings stored in a database table to an <see cref="IConfigurationBuilder"/>.</summary> |
| | | 8 | | public static class APPSettingsRegistration |
| | | 9 | | { |
| | | 10 | | /// <summary> |
| | | 11 | | /// Starts adding a configuration source that reads <typeparamref name="TSettingsTable"/> rows through EF Core. |
| | | 12 | | /// Nothing is added until you call <c>Build( services )</c>. |
| | | 13 | | /// </summary> |
| | | 14 | | /// <typeparam name="TSettingsTable">The settings entity.</typeparam> |
| | | 15 | | /// <typeparam name="TDbContext">The context that holds the settings table.</typeparam> |
| | | 16 | | /// <param name="configuration">The configuration builder to add the source to.</param> |
| | | 17 | | /// <param name="serviceProvider"> |
| | | 18 | | /// Used to resolve <see cref="IDbContextFactory{TContext}"/> when <c>WithDbContextFactory</c> isn't called. Optiona |
| | | 19 | | /// </param> |
| | | 20 | | /// <returns>A builder for the source options.</returns> |
| | | 21 | | /// <exception cref="ArgumentNullException"><paramref name="configuration"/> is <see langword="null"/>.</exception> |
| | | 22 | | /// <example> |
| | | 23 | | /// <code> |
| | | 24 | | /// builder.Configuration.AddEFConfiguration<AppSetting, AppDbContext>() |
| | | 25 | | /// .WithDbContextFactory( new PooledDbContextFactory<AppDbContext>( options ) ) |
| | | 26 | | /// .WithReloader() |
| | | 27 | | /// .Build( builder.Services ); |
| | | 28 | | /// </code> |
| | | 29 | | /// </example> |
| | | 30 | | public static IEFConfigurationBuilder<TSettingsTable, TDbContext> AddEFConfiguration< TSettingsTable, TDbContext >( |
| | | 31 | | this IConfigurationBuilder configuration, IServiceProvider? serviceProvider = null |
| | | 32 | | ) |
| | | 33 | | where TSettingsTable : class, IEFConfigurationValue, new() |
| | | 34 | | where TDbContext : DbContext |
| | | 35 | | { |
| | 56 | 36 | | ArgumentNullException.ThrowIfNull( configuration ); |
| | | 37 | | |
| | 56 | 38 | | return new EFConfigurationBuilder<TSettingsTable, TDbContext>( configuration, serviceProvider ); |
| | | 39 | | } |
| | | 40 | | } |