You've already forked Extensions.Configuration.EntityFrameworkCore
Remove unnecessary TSetting type parameter from ISettingsDbContext & just use ISetting instead
This commit is contained in:
@@ -19,7 +19,7 @@ public static class ServiceCollectionExtensions
|
||||
/// <remarks>If your connection string contains a password then this method may not work, please use another overload</remarks>
|
||||
/// <exception cref="NullReferenceException">If your <typeparamref name="TDbContext"/> does not have a connection string</exception>
|
||||
public static IServiceCollection AddSqlServerNotificationConfigurationReloadService<TDbContext, TSetting>(this IServiceCollection services)
|
||||
where TDbContext : DbContext, ISettingsDbContext<DbSet<TSetting>, TSetting>
|
||||
where TDbContext : DbContext, ISettingsDbContext<IQueryable<TSetting>>
|
||||
where TSetting : class, ISetting
|
||||
{
|
||||
var optionsBuilder = services.AddCoreServices<TDbContext, TSetting>();
|
||||
@@ -49,7 +49,7 @@ public static class ServiceCollectionExtensions
|
||||
/// </param>
|
||||
/// <returns>The service collection it was called on now with added services</returns>
|
||||
public static IServiceCollection AddSqlServerNotificationConfigurationReloadService<TDbContext, TSetting>(this IServiceCollection services, Action<Options> configure)
|
||||
where TDbContext : DbContext, ISettingsDbContext<DbSet<TSetting>, TSetting>
|
||||
where TDbContext : DbContext, ISettingsDbContext<IQueryable<TSetting>>
|
||||
where TSetting : class, ISetting
|
||||
{
|
||||
var optionsBuilder = services.AddCoreServices<TDbContext, TSetting>();
|
||||
@@ -61,7 +61,7 @@ public static class ServiceCollectionExtensions
|
||||
|
||||
|
||||
private static OptionsBuilder<Options> AddCoreServices<TDbContext, TSetting>(this IServiceCollection services)
|
||||
where TDbContext : DbContext, ISettingsDbContext<DbSet<TSetting>, TSetting>
|
||||
where TDbContext : DbContext, ISettingsDbContext<IQueryable<TSetting>>
|
||||
where TSetting : class, ISetting
|
||||
{
|
||||
services.AddSingleton(static provider =>
|
||||
|
||||
@@ -57,7 +57,7 @@ public record Setting : ISetting
|
||||
public required string Value { get; set; }
|
||||
}
|
||||
|
||||
public class MyDbContext(DbContextOptions<MyDbContext> options) : DbContext(options), ISettingsDbContext<DbSet<Setting>, Setting>, ISettingsDbContextFactory<MyDbContext>
|
||||
public class MyDbContext(DbContextOptions<MyDbContext> options) : DbContext(options), ISettingsDbContext<DbSet<Setting>>, ISettingsDbContextFactory<MyDbContext>
|
||||
{
|
||||
public DbSet<Setting> Settings { get; set; }
|
||||
|
||||
@@ -72,7 +72,7 @@ builder.Configuration.AddJsonFile("appsettings.json")
|
||||
...
|
||||
.AddUserSecrets<Program>(); // or wherever your connection string lives
|
||||
|
||||
builder.Configuration.AddDbSet<MyDbContext, Setting>(dbContextOptions => dbContextOptions.UseSqlServer(builder.Configuration.GetConnectionString("Default")));
|
||||
builder.Configuration.AddDbContext<MyDbContext>(dbContextOptions => dbContextOptions.UseSqlServer(builder.Configuration.GetConnectionString("Default")));
|
||||
|
||||
...
|
||||
// Add the SqlServerNotificationConfigurationReloader background service and supporting services to obtain setting reloading functionalty
|
||||
|
||||
@@ -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<TDbContext, TSetting> : Microsoft.Extensions.Hosting.BackgroundService
|
||||
where TDbContext : DbContext, ISettingsDbContext<DbSet<TSetting>, TSetting>
|
||||
where TDbContext : DbContext, ISettingsDbContext<IQueryable<TSetting>>
|
||||
where TSetting : class, ISetting
|
||||
{
|
||||
private static string? _changesQueryTemplate;
|
||||
|
||||
Reference in New Issue
Block a user