Extensions.Options.EntityFrameworkCore 2.0.1

dotnet add package Extensions.Options.EntityFrameworkCore --version 2.0.1
                    
NuGet\Install-Package Extensions.Options.EntityFrameworkCore -Version 2.0.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="Extensions.Options.EntityFrameworkCore" Version="2.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Extensions.Options.EntityFrameworkCore" Version="2.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Extensions.Options.EntityFrameworkCore" />
                    
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 Extensions.Options.EntityFrameworkCore --version 2.0.1
                    
#r "nuget: Extensions.Options.EntityFrameworkCore, 2.0.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 Extensions.Options.EntityFrameworkCore@2.0.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=Extensions.Options.EntityFrameworkCore&version=2.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Extensions.Options.EntityFrameworkCore&version=2.0.1
                    
Install as a Cake Tool

Extensions.Options.EntityFrameworkCore

A Microsoft.Extensions.Configuration provider that reads key/value pairs from a database table through a regular EF Core DbContext — no need to write your own IConfigurationProvider from scratch.

Features

Aspect Value
Data source any table, through your own EF Core DbContext
Database any database with an EF Core provider (PostgreSQL, SQL Server, SQLite, Oracle, etc.) — chosen by the consumer, the library isn't tied to a specific database
Periodic refresh optional, via options.PeriodicalRefreshInterval
Resilience to database outages retry with exponential backoff (options.Retry), without crashing the application
EF Core SQL logging disabled by default
Diagnostics opt-in, through ILogger — silent unless explicitly requested
Row filtering any LINQ predicate (options.Filter)

The library never resolves TDbContext from the application's DI container. Instead, it builds its own DbContextOptionsBuilder<TDbContext> from options.ConfigureDbContext. This removes any dependency on the order services are registered in — database access behaves the same way for the initial read and for every periodic refresh.

Installation

dotnet add package Extensions.Options.EntityFrameworkCore

Target frameworks: net8.0, net10.0.

Quick start

The configuration table entity implements IConfigEntity:

public class DbOptionEntity : IConfigEntity
{
    public string Name { get; set; } = default!;
    public string? Value { get; set; }
}

TDbContext is any DbContext with the standard TDbContext(DbContextOptions<TDbContext> options) constructor and a DbSet<DbOptionEntity> in its model (this can be your application's main DbContext or a separate one dedicated to configuration).

var builder = WebApplication.CreateBuilder(args);

builder.Configuration.AddEntityFrameworkConfiguration<AppDbContext, DbOptionEntity>(builder.Services, options =>
{
    options.ConfigureDbContext = o => o.UseNpgsql(builder.Configuration.GetConnectionString("Default"));
    options.Filter = e => e.Value != null;
    options.PeriodicalRefreshInterval = TimeSpan.FromSeconds(60);
    options.Diagnostics.LogReloadEvents = true; // optional, silent by default
});

Values from the table are then available as regular configuration — through IConfiguration, IOptions<T>, etc., alongside every other configuration source in the application.

Options

Property Purpose
ConfigureDbContext (required) configures DbContextOptionsBuilder<TDbContext>: connection string, database provider
DbContextFactory escape hatch — a custom TDbContext factory, for a non-standard constructor
Filter a LINQ predicate (Expression<Func<TConfigEntity, bool>>) to select rows
PeriodicalRefreshInterval the refresh interval; if not set, configuration is read only once at startup
Retry.MaxAttempts / InitialDelay / BackoffFactor / MaxDelay the retry policy applied when the database is unavailable
Diagnostics.LogReloadEvents enable structured logging of successful reload events

Якщо у вашого TDbContext конструктор приймає більше ніж один параметр (наприклад, окремий ILogger<TDbContext> для власного логування контексту), дефолтне створення інстансу впаде з MissingMethodException. Явно вкажіть фабрику:

options.DbContextFactory = o => new AppDbContext(o, NullLogger<AppDbContext>.Instance);

Передавати сюди "справжній" ILogger з DI не потрібно і не варто — цей DbContext навмисно ізольований від DI застосунку (див. вище), а SQL-логування й так вимкнено за замовчуванням. NullLogger<TDbContext>.Instance — правильний дефолт для цього параметра.

Version 2.0.0 is an intentional breaking change from 1.0.0: UseServiceProvider was removed, AddEntityFramework was renamed to AddEntityFrameworkConfiguration with a new signature, and netstandard2.0 support was dropped. See CHANGELOG.md for details.

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 is compatible.  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
2.0.1 126 8/4/2026
2.0.0 137 8/3/2026