ConfigurationRepository 1.0.0

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

ConfigurationRepository

A class library for ASP .NET Core applications for using databases as configuration repositories.

Ms Sql Server + Dapper:

Let's assume that we have a database that stores a configuration table as key-value pairs:

create table Configuration
(
    [Key]   varchar(800)  not null primary key clustered,
    [Value] nvarchar(max)     null
);

insert Configuration ([Key], [Value])
values ('Logging:LogLevel:Default', N'Information'),
       ('Logging:LogLevel:Microsoft.AspNetCore', N'Warning');

This script defines a table with non-nullable Key column used as primary key and nullable Value column. The hierarchy of keys is linearized by colon [:] separators. The names of the table, columns and keys/indexes on them can be any.

So then in our application Program.cs file we may add a configuration provider like this:

var builder = WebApplication.CreateBuilder(args);

var connectionString = builder.Configuration.GetConnectionString("Dapper");

builder.Configuration.AddDapperRepository(
    repository => repository
        .UseDbConnectionFactory(() => new SqlConnection(connectionString))
        .WithSelectConfigurationQuery("select \"Key\", \"Value\" from Configuration"));

var app = builder.Build();

app.Run();

Here we:

  • extract connection string named "Dapper" from existing configuration providers (i.e. appsettings,json);
  • add database repository using Dapper with AddDapperRepository() extension method;
  • define database connection factory that will create database connection for our provider using UseDbConnectionFactory() extension method and our connection string;
  • define the select configuration query with WithSelectConfigurationQuery() extension method.

If our database source can change at any time in any way we may also add configuration reloader that with periodically reload our configuration from database:

var builder = WebApplication.CreateBuilder(args);

var connectionString = builder.Configuration.GetConnectionString("Dapper");

builder.Configuration.AddDapperRepository(
    repository => repository
        .UseDbConnectionFactory(() => new SqlConnection(connectionString))
        .WithSelectConfigurationQuery("select \"Key\", \"Value\" from Configuration"),
    source => source.WithPeriodicalReload());

builder.Services.AddConfigurationReloader();

var app = builder.Build();

app.Run();

Here we additionaly:

  • define that our configuration provider source will use PeriodicalReload background service;
  • register PeriodicalReload background service in our service collection.

We can define reload period as a time span passed as a parameter to WithPeriodicalReload() exstension method.

What if our config in database is too heavy to reload it frequently and we want to minimize our network traffic? Let`s just version our configurations adding a rowversion column to the configuration table:

create table Configuration
(
    [Key]     varchar(800)  not null primary key clustered,
    [Value]   nvarchar(max)     null,
    [Version] rowversion    not null unique
);

insert Configuration ([Key], [Value])
values ('Logging:LogLevel:Default', N'Information'),
       ('Logging:LogLevel:Microsoft.AspNetCore', N'Warning');

Here we additionaly:

  • add a Version column of type rowversion to Configuration table;
  • mark Version column with uniqe constraint to get an indexed column.

Then we make our configuration versioned by adding SelectCurrentVersionQuery to our repository:

var builder = WebApplication.CreateBuilder(args);

var connectionString = builder.Configuration.GetConnectionString("Dapper");

builder.Configuration.AddDapperRepository(
    repository => repository
        .UseDbConnectionFactory(() => new SqlConnection(connectionString))
        .WithSelectConfigurationQuery("select \"Key\", \"Value\" from Configuration")
        .WithSelectCurrentVersionQuery("select max(\"Version\") from Configuration"),
    source => source.WithPeriodicalReload());

builder.Services.AddConfigurationReloader();

var app = builder.Build();

app.Run();

Here we additionaly add WithSelectCurrentVersionQuery() extension method passing query that selects current configuration version.

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 (4)

Showing the top 4 NuGet packages that depend on ConfigurationRepository:

Package Downloads
ConfigurationRepository.EntityFramework

Configuration repository provider that stored in a database and accessed via EfCore ORM.

ConfigurationRepository.SqlClient

Configuration repository provider that stored in an MS SQL Server database and accessed via SqlClient library.

ParametrizedConfiguration

Parametrized configuration provider. A configuration that may contain parameter placeholders replaceable with values. Parameter values substitute with keys from the same configuration.

ConfigurationRepository.Dapper

Configuration repository provider that stored in a database and accessed via Dapper ORM.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 107 6/16/2025