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
<PackageReference Include="Extensions.Options.EntityFrameworkCore" Version="2.0.1" />
<PackageVersion Include="Extensions.Options.EntityFrameworkCore" Version="2.0.1" />
<PackageReference Include="Extensions.Options.EntityFrameworkCore" />
paket add Extensions.Options.EntityFrameworkCore --version 2.0.1
#r "nuget: Extensions.Options.EntityFrameworkCore, 2.0.1"
#:package Extensions.Options.EntityFrameworkCore@2.0.1
#addin nuget:?package=Extensions.Options.EntityFrameworkCore&version=2.0.1
#tool nuget:?package=Extensions.Options.EntityFrameworkCore&version=2.0.1
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 | Versions 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. |
-
net10.0
- Microsoft.EntityFrameworkCore (>= 10.0.0)
- Microsoft.Extensions.Configuration (>= 10.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.0)
-
net8.0
- Microsoft.EntityFrameworkCore (>= 8.0.0)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.