RAIC.Extensions.Configuration.EntityFrameworkCore
0.1.1
dotnet add package RAIC.Extensions.Configuration.EntityFrameworkCore --version 0.1.1
NuGet\Install-Package RAIC.Extensions.Configuration.EntityFrameworkCore -Version 0.1.1
<PackageReference Include="RAIC.Extensions.Configuration.EntityFrameworkCore" Version="0.1.1" />
<PackageVersion Include="RAIC.Extensions.Configuration.EntityFrameworkCore" Version="0.1.1" />
<PackageReference Include="RAIC.Extensions.Configuration.EntityFrameworkCore" />
paket add RAIC.Extensions.Configuration.EntityFrameworkCore --version 0.1.1
#r "nuget: RAIC.Extensions.Configuration.EntityFrameworkCore, 0.1.1"
#:package RAIC.Extensions.Configuration.EntityFrameworkCore@0.1.1
#addin nuget:?package=RAIC.Extensions.Configuration.EntityFrameworkCore&version=0.1.1
#tool nuget:?package=RAIC.Extensions.Configuration.EntityFrameworkCore&version=0.1.1
RAIC.Extensions.Configuration.EntityFrameworkCore
This library is a Microsoft.Extensions.Configuration.IConfigurationProvider that reads settings from a DbSet<ISetting> Settings property
present on your Entity Framework Core DbContext.
Goals
- Usable with minimal constraints on your entity model
- Follows conventional configuration patterns
IOptionsMonitorupdate support through optional opt-in services (seeRAIC.Extensions.Configuration.EntityFrameworkCore.PostgreSQL&RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer)
Requirements
- .NET 8
Gotchas
- Setting values cannot be
null(as signified by theRequiredAttributeonISetting.Value) - Setting keys should not contain the
=character (similar toCommandLineConfigurationProvider&EnvironmentVariablesConfigurationProvider)
Usage Example
using RAIC.Extensions.Configuration.EntityFrameworkCore.Extensions;
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 whereever your connection string lives
// obtain connection string from preliminary config so can initialise other settings from DbContext
builder.Configuration.AddDbContext<MyDbContext>(dbContextOptions => dbContextOptions.UseNpgsql(builder.Configuration.GetConnectionString("Default")));
...
await builder.Build().RunAsync(); // use config as normal
Read more about Configuration on the Microsoft Docs site.
| 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 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. |
-
net8.0
- Microsoft.EntityFrameworkCore.Relational (>= 8.0.0 && < 11.0.0)
- Microsoft.Extensions.Configuration (>= 8.0.0 && < 11.0.0)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on RAIC.Extensions.Configuration.EntityFrameworkCore:
| Package | Downloads |
|---|---|
|
RAIC.Extensions.Configuration.EntityFrameworkCore.SqlServer
Adds "reload on change" support to RAIC.Extensions.Configuration.EntityFrameworkCore for Microsoft SQL Server |
|
|
RAIC.Extensions.Configuration.EntityFrameworkCore.PostgreSQL
Adds "reload on change" support to RAIC.Extensions.Configuration.EntityFrameworkCore for PostgreSQL |
GitHub repositories
This package is not used by any popular GitHub repositories.