RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer 0.1.1

dotnet add package RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer --version 0.1.1
                    
NuGet\Install-Package RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer -Version 0.1.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer" Version="0.1.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer" Version="0.1.1" />
                    
Directory.Packages.props
<PackageReference Include="RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer --version 0.1.1
                    
#r "nuget: RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer, 0.1.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer@0.1.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer&version=0.1.1
                    
Install as a Cake Addin
#tool nuget:?package=RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer&version=0.1.1
                    
Install as a Cake Tool

RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer

This library enhances RAIC.Extensions.Configuration.EntityFrameworkCore with support for reload on update the via the query change notifications capability exposed by Microsoft.Data.SqlClient.SqlDependency along with SQL Server's Change Tracking feature.

Goals

  1. No polling!
  2. Updates happen in background via a hosted service implementation
  3. Only update settings which change rather than updating them all

Requirements

  • .NET 8

Gotchas

  • Won't work with Azure SQL until Microsoft adds/enables Service Broker support
  • Setting values cannot be null (as signified by the RequiredAttribute on ISetting.Value)
  • Consider adding ConnectRetryCount and ConnectRetryInterval parameters to your connection string if not already present

Known Issues

  • Not tested under load
  • Transient failure detection logic is not well tested given the challenges in reproducing these issues

Configuration Options

There are two properties which can be configured (cf. the SqlServerNotificationConfigurationReloaderOptions POCO)

  1. ConnectionString - the full connection string for the SQL Server instance
  2. TransientErrors - the list of SqlError.Number values that will be treated as transient if present in a thrown SqlException's Errors collection while listening for or processing notifications (ie. reconnection will be attempted if any are present)

Setup

For SqlServerNotificationConfigurationReloader to work it requires Change Tracking to be enable on the Settings table (and therefore also on the database itself) eg:

ALTER DATABASE myDatabase
SET CHANGE_TRACKING = ON (AUTO_CLEANUP = ON);

ALTER TABLE dbo.Settings
ENABLE CHANGE_TRACKING;

Recommend adding your SQL to the migration which adds the Settings table/view (or a new migration if that table/view already exists).

Usage Example


using RAIC.Extensions.Configuration.EntityFrameworkCore;
using RAIC.Extensions.Configuration.EntityFrameworkCore.Extensions;
using RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer.Extensions;

[Table("settings", Schema = "dbo")] // Need to explicitly set schema somehow, this is one way to do it
public record Setting : ISetting
{
    [Key]
    public required string Key { get; set; }

    [Required]
    public required string Value { get; set; }
}

public class MyDbContext(DbContextOptions<MyDbContext> options) : DbContext(options), ISettingsDbContext<DbSet<Setting>>, ISettingsDbContextFactory<MyDbContext>
{
    public DbSet<Setting> Settings { get; set; }

    public static MyDbContext Create(DbContextOptions<MyDbContext> options) => new(options);
}


var builder = Host.CreateApplicationBuilder(args); // or  WebApplication.CreateBuilder(args); 

// build an initial configuration
builder.Configuration.AddJsonFile("appsettings.json")
                     ...
                     .AddUserSecrets<Program>(); // or wherever your connection string lives

builder.Configuration.AddDbContext<MyDbContext>(dbContextOptions => dbContextOptions.UseSqlServer(builder.Configuration.GetConnectionString("Default")));

...
// Add the SqlServerNotificationConfigurationReloader background service and supporting services to obtain setting reloading functionalty
builder.Services.AddSqlServerNotificationConfigurationReloadService<MyDbContext, Settings>(); // uses connection string from MyDbContext. Other overrides exist if this doesn't work for you - see cods docs

await builder.Build().RunAsync(); // use config as normal

Read more about Configuration and Options on the Microsoft Docs site.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.1.1 103 1/7/2026
0.0.1 303 12/8/2025