MrRabbit.Extensions.Configuration.Database
1.0.0
dotnet add package MrRabbit.Extensions.Configuration.Database --version 1.0.0
NuGet\Install-Package MrRabbit.Extensions.Configuration.Database -Version 1.0.0
<PackageReference Include="MrRabbit.Extensions.Configuration.Database" Version="1.0.0" />
<PackageVersion Include="MrRabbit.Extensions.Configuration.Database" Version="1.0.0" />
<PackageReference Include="MrRabbit.Extensions.Configuration.Database" />
paket add MrRabbit.Extensions.Configuration.Database --version 1.0.0
#r "nuget: MrRabbit.Extensions.Configuration.Database, 1.0.0"
#:package MrRabbit.Extensions.Configuration.Database@1.0.0
#addin nuget:?package=MrRabbit.Extensions.Configuration.Database&version=1.0.0
#tool nuget:?package=MrRabbit.Extensions.Configuration.Database&version=1.0.0
<h1 align="center">DatabaseConfigurationProvider</h1>
<p align="center"> <a href="https://dotnet.microsoft.com/"><img src="https://img.shields.io/badge/.NET-10-512bd4?logo=dotnet" alt=".NET 10"></a> <a href="https://www.nuget.org/packages/MrRabbit.Extensions.Configuration.Database"><img src="https://img.shields.io/nuget/v/MrRabbit.Extensions.Configuration.Database?logo=nuget&color=004880" alt="NuGet"></a> <a href="https://opensource.org/licenses/MIT"><img src="https://img.shields.io/badge/License-MIT-blue.svg" alt="License: MIT"></a> </p>
<p align="center"> A .NET library that extends the <code>Microsoft.Extensions.Configuration</code> system to support <b>database-backed configuration</b> sources with <b>read and write</b> capabilities.<br> Store and retrieve application settings from relational databases, with support for dynamic updates and strongly-typed options. </p>
<p align="center"> Feel free to report issues or suggest improvements to enhance the functionality and usability of this library. </p>
๐ Table of Contents
- โจ Features
- ๐ Supported Database Providers
- ๐ Getting Started
- โ๏ธ Advanced Usage
- ๐๏ธ Database Schema
- โ ๏ธ Limitations
- ๐ Changelog
- ๐ License
โจ Features
| Feature | Description | |
|---|---|---|
| ๐๏ธ | Database-Backed Configuration | Store application settings in SQL databases instead of static files |
| ๐ | Multiple Database Providers | Support for SQLite and SQL Server |
| โ๏ธ | Read/Write Support | Read configurations and update them at runtime |
| ๐ข | Supported Value Types | bool ยท char ยท decimal ยท double ยท float ยท int ยท long ยท string ยท DateTime ยท DateOnly ยท TimeOnly ยท TimeSpan ยท Guid |
| ๐ฆ | Collection Support | One-dimensional arrays and enumerables of a supported type (e.g. List<string>, string[]) |
| ๐๏ธ | Hierarchical Configuration | Support for nested configuration objects |
| ๐ | Seamless Integration | Works with the existing Microsoft.Extensions.Configuration system |
๐ Supported Database Providers
| Provider | Package Required | Provider Name | Tested on version |
|---|---|---|---|
| SQLite | Microsoft.Data.Sqlite | Provider.SQLite |
|
| SQL Server | Microsoft.Data.SqlClient | Provider.MsSql |
docker image mcr.microsoft.com/mssql/server:2025-latest |
๐ Getting Started
Installation
Install the package via NuGet Package Manager:
dotnet add package MrRabbit.Extensions.Configuration.Database
Additionally, install the database provider package you intend to use:
For SQLite:
dotnet add package Microsoft.Data.Sqlite
For SQL Server:
dotnet add package Microsoft.Data.SqlClient
Basic Configuration
Add the database configuration provider to your IConfigurationBuilder:
using Microsoft.Extensions.Configuration;
using MrRabbit.Extensions.Configuration.Database;
var configuration = new ConfigurationBuilder()
.AddDatabaseProvider(options =>
{
options.UseDatabase(Provider.SQLite, "Data Source=config.db");
})
.Build();
The library automatically registers the provider by calling DbProviderFactories.RegisterFactory(). To disable this behavior:
options.UseDatabase(Provider.SQLite, connectionString, registerDbProviderFactory: false);
Register Services
Configure options to be writable in your service collection:
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Configuration;
builder.Services.ConfigureWritable<AppOptions>(builder.Configuration.GetSection("App"));
Reading Configuration
Use the standard IOptionsMonitor<T> interface to read configuration:
public class MyService
{
private readonly IOptionsMonitor<AppOptions> _options;
public MyService(IOptionsMonitor<AppOptions> options)
{
_options = options;
}
public void DoSomething()
{
var currentValue = _options.CurrentValue.ConnectionString;
}
}
public class AppOptions
{
public string ConnectionString { get; set; }
public int MaxRetries { get; set; }
public bool EnableLogging { get; set; }
}
Writing Configuration
Use the IWritableOptionsMonitor<T> interface to read and update configuration:
public class SettingsManager
{
private readonly IWritableOptionsMonitor<AppOptions> _options;
public SettingsManager(IWritableOptionsMonitor<AppOptions> options)
{
_options = options;
}
public void UpdateSettings()
{
var updated = new AppOptions
{
ConnectionString = "Server=localhost;Database=NewDb",
MaxRetries = 5,
EnableLogging = true
};
_options.Update(updated);
// Changes are immediately reflected
var current = _options.CurrentValue;
}
}
โ๏ธ Advanced Usage
Complex Objects
The library supports nested configuration objects:
public class ApplicationSettings
{
public DatabaseSettings Database { get; set; }
public LoggingSettings Logging { get; set; }
}
public class DatabaseSettings
{
public string ConnectionString { get; set; }
public int Timeout { get; set; }
}
public class LoggingSettings
{
public string Level { get; set; }
public string Path { get; set; }
}
// Usage
services.ConfigureWritable<ApplicationSettings>(
configuration.GetSection("App")
);
Collections and Arrays
Arrays and enumerable properties are fully supported:
public class ApiSettings
{
public string[] AllowedOrigins { get; set; }
public List<string> ApiKeys { get; set; }
}
// Usage
var settings = new ApiSettings
{
AllowedOrigins = new[] { "http://localhost", "https://example.com" },
ApiKeys = new List<string> { "key1", "key2", "key3" }
};
writableOptions.Update(settings);
Custom Table Configuration
To customize table and column names, you can configure the provider options:
using Microsoft.Extensions.Configuration;
using MrRabbit.Extensions.Configuration.Database;
var configuration = new ConfigurationBuilder()
.AddDatabaseProvider(options =>
{
options.UseDatabase(Provider.SQLite, "Data Source=config.db")
.UseTable(t => t
.UseTable("MyTable")
.UseKeyColumn("MyKey")
.UseValueColumn("MyValue")
.UseBaseKeyColumn("MyBaseKey"));
})
.Build();
Transactions
If your application requires transactional updates to configuration, you can modify the configuration table within a transaction scope and call ReloadDatabaseConfigurationProvider after commit to apply changes:
Entity Framework Example
internal class AppDbContext : DbContext
{
public override async Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
{
var configurationChanged = ChangeTracker.Entries<ConfigurationEntry>().Any();
var result = await base.SaveChangesAsync(cancellationToken);
if (configurationChanged)
{
var configuration = this.GetService<IConfiguration>();
configuration.ReloadDatabaseConfigurationProvider();
}
return result;
}
}
๐๏ธ Database Schema
The provider stores configuration in a flat table named ConfigurationEntries:
| Column | Type | Index | Description |
|---|---|---|---|
| Key | MsSql: NVARCHAR(450) <br> SQLite: TEXT |
Unique | The configuration key path (e.g., App:Database:ConnectionString) |
| Value | MsSql: NVARCHAR(MAX) <br> SQLite: TEXT |
โ | The serialized value |
| BaseKey | MsSql: NVARCHAR(450) <br> SQLite: TEXT |
Index | For array items, references the parent key |
Example data:
| Key | Value | BaseKey |
|---|---|---|
App:ConnectionString |
Server=localhost |
NULL |
App:MaxRetries |
5 |
NULL |
App:ApiKeys:0 |
key1 |
App:ApiKeys |
App:ApiKeys:1 |
key2 |
App:ApiKeys |
App:Database:Timeout |
30 |
NULL |
โ ๏ธ Limitations
Database Providers
External changes to the ConfigurationEntries table are not automatically detected. To apply changes made outside the application, restart the application or call:
configuration.ReloadDatabaseConfigurationProvider();
SQL Server: Maximum key length is 450 characters due to index limitations on NVARCHAR(450).
Concurrency
The library does not implement optimistic concurrency control or locking mechanisms. In multi-instance deployments:
| Scenario | Behavior |
|---|---|
| Concurrent writes | Last write wins |
| Parallel updates | May overwrite each other |
Performance
| Operation | Behavior |
|---|---|
| Write | Performs database I/O per call |
| Read | Cached by the configuration provider |
Schema Management
- The table is auto-created on first use
- Schema migrations are not automatically handled
Null Handling
Setting a value to null or empty string will delete the entry from the database.
Arrays and enumerables set to null will be removed entirely.
๐ Changelog
1.0.0
- first release
๐ License
This project is licensed under the terms specified in the repository.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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.Extensions.Configuration.Abstractions (>= 10.0.0 && < 11.0.0)
- Microsoft.Extensions.Options (>= 10.0.0 && < 11.0.0)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.0 && < 11.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 |
|---|---|---|
| 1.0.0 | 92 | 5/4/2026 |
| 0.0.2-preview | 110 | 3/30/2026 |
| 0.0.1-preview | 102 | 3/30/2026 |