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
                    
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="GovUK.Dfe.CoreLibs.ApplicationSettings" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="GovUK.Dfe.CoreLibs.ApplicationSettings" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="GovUK.Dfe.CoreLibs.ApplicationSettings" />
                    
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 GovUK.Dfe.CoreLibs.ApplicationSettings --version 0.1.0
                    
#r "nuget: GovUK.Dfe.CoreLibs.ApplicationSettings, 0.1.0"
                    
#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 GovUK.Dfe.CoreLibs.ApplicationSettings@0.1.0
                    
#: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=GovUK.Dfe.CoreLibs.ApplicationSettings&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=GovUK.Dfe.CoreLibs.ApplicationSettings&version=0.1.0
                    
Install as a Cake Tool

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 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.0 2,309 4/13/2026
0.1.0-prerelease-194 110 4/13/2026