GovUK.Dfe.CoreLibs.ApplicationSettings
0.1.0
Prefix Reserved
dotnet add package GovUK.Dfe.CoreLibs.ApplicationSettings --version 0.1.0
NuGet\Install-Package GovUK.Dfe.CoreLibs.ApplicationSettings -Version 0.1.0
<PackageReference Include="GovUK.Dfe.CoreLibs.ApplicationSettings" Version="0.1.0" />
<PackageVersion Include="GovUK.Dfe.CoreLibs.ApplicationSettings" Version="0.1.0" />
<PackageReference Include="GovUK.Dfe.CoreLibs.ApplicationSettings" />
paket add GovUK.Dfe.CoreLibs.ApplicationSettings --version 0.1.0
#r "nuget: GovUK.Dfe.CoreLibs.ApplicationSettings, 0.1.0"
#:package GovUK.Dfe.CoreLibs.ApplicationSettings@0.1.0
#addin nuget:?package=GovUK.Dfe.CoreLibs.ApplicationSettings&version=0.1.0
#tool nuget:?package=GovUK.Dfe.CoreLibs.ApplicationSettings&version=0.1.0
GovUK.Dfe.CoreLibs.ApplicationSettings
A generic, database-backed application settings management library for DfE applications. This package provides a consistent way to manage, retrieve, and update application settings using Entity Framework Core and integrates with .NET configuration and dependency injection.
Features
- Store and retrieve application settings from a database
- Integrates with Microsoft.Extensions.Configuration and Microsoft.Extensions.Options
- Supports caching for improved performance
- Designed for use with .NET 8 and Entity Framework Core
Installation
Add the NuGet package to your project:
dotnet add package GovUK.Dfe.CoreLibs.ApplicationSettings
Or via Visual Studio NuGet Package Manager.
Integration Guide
Follow these steps to integrate the package with your existing application:
1. Add the ApplicationSetting Entity to Your DbContext
Add a DbSet<ApplicationSetting> property to your DbContext:
public class AppSettingsDbContext : DbContext
{
public DbSet<ApplicationSetting> ApplicationSettings { get; set; }
// ...
}
Using ApplicationSettings with an Existing DbContext
You do not need to create a dedicated DbContext for application settings.
If you have an existing DbContext, simply add a DbSet<ApplicationSetting> property and call the ConfigureApplicationSettings extension method in your OnModelCreating override:
public class MyAppDbContext : DbContext
{
public DbSet<ApplicationSetting> ApplicationSettings { get; set; }
// ... your other DbSets
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Configure ApplicationSetting entity for use in your existing context
modelBuilder.ConfigureApplicationSettings(schema: "dbo", tableName: "ApplicationSettings");
base.OnModelCreating(modelBuilder);
}
}
This ensures the ApplicationSetting entity is mapped and configured correctly alongside your other entities.
2. Configure the ApplicationSetting Entity
In your DbContext, override OnModelCreating and use the provided extension method to configure the entity:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
// Configure ApplicationSetting entity with optional schema and table name
modelBuilder.ConfigureApplicationSettings(schema: "dbo", tableName: "ApplicationSettings");
base.OnModelCreating(modelBuilder);
}
Or, if you are using options from DI:
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.ConfigureApplicationSettings(options);
base.OnModelCreating(modelBuilder);
}
About the Extension Methods
The package provides two extension methods for configuring the ApplicationSetting entity:
ConfigureApplicationSettings(this ModelBuilder modelBuilder, string? schema = null, string tableName = "ApplicationSettings")
Configures the entity with the specified schema and table name, setting up keys, indexes, and property constraints.ConfigureApplicationSettings(this ModelBuilder modelBuilder, ApplicationSettingsOptions options)
Configures the entity using options (such as schema) provided via dependency injection.
These methods ensure your database table is correctly structured for storing application settings.
3. Register Services in Dependency Injection
In your Program.cs or Startup.cs:
services.AddDbContext<AppSettingsDbContext>(options =>
options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
services.AddApplicationSettings<AppSettingsDbContext>();
4. Apply Migrations
Generate and apply EF Core migrations to create the ApplicationSettings table:
dotnet ef migrations add AddApplicationSettings
dotnet ef database update
5. Access Settings in Your Code
Inject IApplicationSettings where needed:
public class MyService
{
private readonly IApplicationSettings _settings;
public MyService(IApplicationSettings settings)
{
_settings = settings;
}
public async Task<string> GetSettingAsync()
{
return await _settings.GetAsync<string>("MySettingKey");
}
}
| 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 (>= 8.0.11)
- Microsoft.EntityFrameworkCore.SqlServer (>= 8.0.11)
- Microsoft.Extensions.Caching.Memory (>= 8.0.1)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 8.0.0)
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.0 | 2,309 | 4/13/2026 |
| 0.1.0-prerelease-194 | 110 | 4/13/2026 |