diff --git a/RAIC.Extensions.Configuration.EntityFrameworkCore.PostgreSQL/README.md b/RAIC.Extensions.Configuration.EntityFrameworkCore.PostgreSQL/README.md index ff2bd8d..28db980 100644 --- a/RAIC.Extensions.Configuration.EntityFrameworkCore.PostgreSQL/README.md +++ b/RAIC.Extensions.Configuration.EntityFrameworkCore.PostgreSQL/README.md @@ -84,7 +84,7 @@ public record Setting : ISetting public required string Value { get; set; } } -public class MyDbContext(DbContextOptions options) : DbContext(options), ISettingsDbContext, Setting>, ISettingsDbContextFactory +public class MyDbContext(DbContextOptions options) : DbContext(options), ISettingsDbContext>, ISettingsDbContextFactory { public DbSet Settings { get; set; } @@ -99,11 +99,11 @@ builder.Configuration.AddJsonFile("appsettings.json") ... .AddUserSecrets(); // or wherever your connection string lives -builder.Configuration.AddDbSet(dbContextOptions => dbContextOptions.UseNpgsql(builder.Configuration.GetConnectionString("Default"))); +builder.Configuration.AddDbContext(dbContextOptions => dbContextOptions.UseNpgsql(builder.Configuration.GetConnectionString("Default"))); ... // Add the PostgreSQLNotificationConfigurationReloader background service and supporting services to obtain setting reloading functionalty -builder.Services.AddPostgreSQLNotificationConfigurationReloadService(); // uses default settings, other overrides exist - see code docs +builder.Services.AddPostgreSQLNotificationConfigurationReloadService(); // uses default settings, other overrides exist - see code docs await builder.Build().RunAsync(); // use config as normal diff --git a/RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer/Extensions/ServiceCollectionExtensions.cs b/RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer/Extensions/ServiceCollectionExtensions.cs index c5210a6..3e7eaf6 100644 --- a/RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer/Extensions/ServiceCollectionExtensions.cs +++ b/RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer/Extensions/ServiceCollectionExtensions.cs @@ -19,7 +19,7 @@ public static class ServiceCollectionExtensions /// If your connection string contains a password then this method may not work, please use another overload /// If your does not have a connection string public static IServiceCollection AddSqlServerNotificationConfigurationReloadService(this IServiceCollection services) - where TDbContext : DbContext, ISettingsDbContext, TSetting> + where TDbContext : DbContext, ISettingsDbContext> where TSetting : class, ISetting { var optionsBuilder = services.AddCoreServices(); @@ -49,7 +49,7 @@ public static class ServiceCollectionExtensions /// /// The service collection it was called on now with added services public static IServiceCollection AddSqlServerNotificationConfigurationReloadService(this IServiceCollection services, Action configure) - where TDbContext : DbContext, ISettingsDbContext, TSetting> + where TDbContext : DbContext, ISettingsDbContext> where TSetting : class, ISetting { var optionsBuilder = services.AddCoreServices(); @@ -61,7 +61,7 @@ public static class ServiceCollectionExtensions private static OptionsBuilder AddCoreServices(this IServiceCollection services) - where TDbContext : DbContext, ISettingsDbContext, TSetting> + where TDbContext : DbContext, ISettingsDbContext> where TSetting : class, ISetting { services.AddSingleton(static provider => diff --git a/RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer/README.md b/RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer/README.md index 1dda7ac..32ee0a9 100644 --- a/RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer/README.md +++ b/RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer/README.md @@ -57,7 +57,7 @@ public record Setting : ISetting public required string Value { get; set; } } -public class MyDbContext(DbContextOptions options) : DbContext(options), ISettingsDbContext, Setting>, ISettingsDbContextFactory +public class MyDbContext(DbContextOptions options) : DbContext(options), ISettingsDbContext>, ISettingsDbContextFactory { public DbSet Settings { get; set; } @@ -72,7 +72,7 @@ builder.Configuration.AddJsonFile("appsettings.json") ... .AddUserSecrets(); // or wherever your connection string lives -builder.Configuration.AddDbSet(dbContextOptions => dbContextOptions.UseSqlServer(builder.Configuration.GetConnectionString("Default"))); +builder.Configuration.AddDbContext(dbContextOptions => dbContextOptions.UseSqlServer(builder.Configuration.GetConnectionString("Default"))); ... // Add the SqlServerNotificationConfigurationReloader background service and supporting services to obtain setting reloading functionalty diff --git a/RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer/SqlServerNotificationConfigurationReloader.cs b/RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer/SqlServerNotificationConfigurationReloader.cs index a8a029c..8063914 100644 --- a/RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer/SqlServerNotificationConfigurationReloader.cs +++ b/RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer/SqlServerNotificationConfigurationReloader.cs @@ -1,7 +1,5 @@ using System.ComponentModel.DataAnnotations; using System.Data; -using System.Runtime.CompilerServices; -using System.Threading.Tasks; using Microsoft.Data.SqlClient; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; @@ -18,7 +16,7 @@ public class SqlServerNotificationConfigurationReloaderOptions // must be public internal class SqlServerNotificationConfigurationReloader : Microsoft.Extensions.Hosting.BackgroundService - where TDbContext : DbContext, ISettingsDbContext, TSetting> + where TDbContext : DbContext, ISettingsDbContext> where TSetting : class, ISetting { private static string? _changesQueryTemplate; diff --git a/RAIC.Extensions.Configuration.EntityFrameworkCore/EntityFrameworkCoreDbSetConfigurationProvider.cs b/RAIC.Extensions.Configuration.EntityFrameworkCore/EntityFrameworkCoreDbSetConfigurationProvider.cs index 3d69704..c55954f 100644 --- a/RAIC.Extensions.Configuration.EntityFrameworkCore/EntityFrameworkCoreDbSetConfigurationProvider.cs +++ b/RAIC.Extensions.Configuration.EntityFrameworkCore/EntityFrameworkCoreDbSetConfigurationProvider.cs @@ -14,9 +14,8 @@ internal interface IEntityFrameworkCoreDbSetConfigurationProvider : IConfigurati } -internal class EntityFrameworkCoreDbSetConfigurationProvider : ConfigurationProvider, IEntityFrameworkCoreDbSetConfigurationProvider - where TDbContext : DbContext, ISettingsDbContext, TSetting> - where TSetting : class, ISetting +internal class EntityFrameworkCoreDbSetConfigurationProvider : ConfigurationProvider, IEntityFrameworkCoreDbSetConfigurationProvider + where TDbContext : DbContext, ISettingsDbContext> { private readonly IEntityFrameworkCoreDbSetConfigurationSource _configurationSource; @@ -41,14 +40,13 @@ internal interface IEntityFrameworkCoreDbSetConfigurationSource wher internal Func DbContextFactory { get; } } -internal class EntityFrameworkCoreDbSetConfigurationSource : IConfigurationSource, IEntityFrameworkCoreDbSetConfigurationSource - where TDbContext : DbContext, ISettingsDbContext, TSetting> - where TSetting : class, ISetting +internal class EntityFrameworkCoreDbSetConfigurationSource : IConfigurationSource, IEntityFrameworkCoreDbSetConfigurationSource + where TDbContext : DbContext, ISettingsDbContext> { public required Func DbContextFactory { get; init; } public IConfigurationProvider Build(IConfigurationBuilder builder) { - return new EntityFrameworkCoreDbSetConfigurationProvider(this); + return new EntityFrameworkCoreDbSetConfigurationProvider(this); } } \ No newline at end of file diff --git a/RAIC.Extensions.Configuration.EntityFrameworkCore/Extensions/ConfigurationBuilderExtensions.cs b/RAIC.Extensions.Configuration.EntityFrameworkCore/Extensions/ConfigurationBuilderExtensions.cs index e558d51..f748864 100644 --- a/RAIC.Extensions.Configuration.EntityFrameworkCore/Extensions/ConfigurationBuilderExtensions.cs +++ b/RAIC.Extensions.Configuration.EntityFrameworkCore/Extensions/ConfigurationBuilderExtensions.cs @@ -10,8 +10,7 @@ public static class ConfigurationBuilderExtensions /// /// Adds a off as a configuration provider to the . /// - /// Type of the which implements - /// Concrete type which implements + /// Type of the which implements both and /// /// a which configures your . eg. /// @@ -19,12 +18,11 @@ public static class ConfigurationBuilderExtensions /// /// /// The - public static IConfigurationBuilder AddDbSet(this IConfigurationBuilder builder, DbContextOptionsTransformer optionsTransformer) - where TDbContext : DbContext, ISettingsDbContext, TSetting>, ISettingsDbContextFactory - where TSetting : class, ISetting + public static IConfigurationBuilder AddDbContext(this IConfigurationBuilder builder, DbContextOptionsTransformer optionsTransformer) + where TDbContext : DbContext, ISettingsDbContext>, ISettingsDbContextFactory { var options = optionsTransformer(new DbContextOptionsBuilder()).Options; - var configurationSource = new EntityFrameworkCoreDbSetConfigurationSource() + var configurationSource = new EntityFrameworkCoreDbSetConfigurationSource() { DbContextFactory = () => TDbContext.Create(options) }; diff --git a/RAIC.Extensions.Configuration.EntityFrameworkCore/ISettingsDbContext.cs b/RAIC.Extensions.Configuration.EntityFrameworkCore/ISettingsDbContext.cs index c5c6752..b00a7e1 100644 --- a/RAIC.Extensions.Configuration.EntityFrameworkCore/ISettingsDbContext.cs +++ b/RAIC.Extensions.Configuration.EntityFrameworkCore/ISettingsDbContext.cs @@ -4,11 +4,10 @@ using Microsoft.EntityFrameworkCore; namespace RAIC.Extensions.Configuration.EntityFrameworkCore; -public interface ISettingsDbContext : IDisposable - where TSettingDbSet : DbSet - where TSetting : class, ISetting +public interface ISettingsDbContext : IDisposable + where TSettings : System.Linq.IQueryable { - TSettingDbSet Settings { get; } + TSettings Settings { get; } } public interface ISettingsDbContextFactory diff --git a/RAIC.Extensions.Configuration.EntityFrameworkCore/README.md b/RAIC.Extensions.Configuration.EntityFrameworkCore/README.md index bbd12a1..13239b1 100644 --- a/RAIC.Extensions.Configuration.EntityFrameworkCore/README.md +++ b/RAIC.Extensions.Configuration.EntityFrameworkCore/README.md @@ -33,7 +33,7 @@ public record Setting : ISetting public required string Value { get; set; } } -public class MyDbContext(DbContextOptions options) : DbContext(options), ISettingsDbContext, Setting>, ISettingsDbContextFactory +public class MyDbContext(DbContextOptions options) : DbContext(options), ISettingsDbContext>, ISettingsDbContextFactory { public DbSet Settings { get; set; } @@ -44,10 +44,11 @@ var builder = Host.CreateApplicationBuilder(args) // or WebApplication.CreateB // build an initial configuration builder.Configuration.AddJsonFile("appsettings.json") + ... .AddUserSecrets(); // or whereever your connection string lives -// obtain connection string from preliminary config so can initialise other settings from DbSet -builder.Configuration.AddDbSet(dbContextOptions => dbContextOptions.UseNpgsql(builder.Configuration.GetConnectionString("Default"))); +// obtain connection string from preliminary config so can initialise other settings from DbContext +builder.Configuration.AddDbContext(dbContextOptions => dbContextOptions.UseNpgsql(builder.Configuration.GetConnectionString("Default"))); ...