MrRabbit.Extensions.Configuration.Database
0.0.2-preview
See the version list below for details.
dotnet add package MrRabbit.Extensions.Configuration.Database --version 0.0.2-preview
NuGet\Install-Package MrRabbit.Extensions.Configuration.Database -Version 0.0.2-preview
<PackageReference Include="MrRabbit.Extensions.Configuration.Database" Version="0.0.2-preview" />
<PackageVersion Include="MrRabbit.Extensions.Configuration.Database" Version="0.0.2-preview" />
<PackageReference Include="MrRabbit.Extensions.Configuration.Database" />
paket add MrRabbit.Extensions.Configuration.Database --version 0.0.2-preview
#r "nuget: MrRabbit.Extensions.Configuration.Database, 0.0.2-preview"
#:package MrRabbit.Extensions.Configuration.Database@0.0.2-preview
#addin nuget:?package=MrRabbit.Extensions.Configuration.Database&version=0.0.2-preview&prerelease
#tool nuget:?package=MrRabbit.Extensions.Configuration.Database&version=0.0.2-preview&prerelease
DatabaseConfigurationProvider
A .NET library that extends the Microsoft.Extensions.Configuration system to support database-backed configuration sources with read and write capabilities. This provider enables storing and retrieving application configuration settings from relational databases, with support for dynamic updates and strongly-typed options.
Fell free to report issues, or suggest improvements to enhance the functionality and usability of this library.
Table of Contents
- Features
- Supported Database Providers
- Getting Started
- Advanced Usage
- Database Schema
- Limitations
- Changelog
- License
Features
- Dot Net: .net 10.0 compatible
- Database-backed Configuration: Store application settings in SQL databases instead of static files
- Multiple Database Providers: Support for SQLite, SQL Server
- Read/Write Support: Not only read configurations but also update at runtime
- Write Type Support: Support for value types bool, char, decimal, double, float, int, long, string, DateTime, DateOnly, TimeOnly, TimeSpan, Guid
- Write Collection Support: Handle one dimension arrays and enumerable properties of one supported type (supported f.e.g. List<string>, string[] not supported f.e.g. List<List<string>>, string[,])
- Hierarchical Configuration: Support for nested configuration objects
- Easy Integration: Seamless integration with existing .NET configuration system
Supported Database Providers
| Provider | Package Required | Provider Name |
|---|---|---|
| SQLite | Microsoft.Data.Sqlite | Provider.SQLite |
| SQL Server | Microsoft.Data.SqlClient | Provider.MsSql |
Getting Started
Basic Configuration
Step 1: 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
Step 2: Configure the Database Provider
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 attempts to auto-register provider by calling <i>DbProviderFactories.RegisterFactory( , )<i> witch can by disabled.
options.UseDatabase(Provider.SQLite, connectionString, registerDbProviderFactory: false);
Step 3: 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; }
}
Reading And 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
While not yet exposed in the public API, the library uses a default table schema. The table is automatically created with the following structure:
CREATE TABLE Configuration (
[Key] NVARCHAR(255) PRIMARY KEY,
[Value] NVARCHAR(MAX),
[BaseKey] NVARCHAR(255)
)
Transactions
If your application requires transactional updates to configuration, you can use change configuration in table within a transaction scope and after commit call ReloadDatabaseConfigurationProvider to apply changes:
EntityFramework example
internal class AppDbContext : DbContext
{
public override Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
{
var configurationChanged = ChangeTracker.Entries<ConfigurationEntry>().Any();
base.SaveChangesAsync(cancellationToken);
if(configurationChanged)
{
var configuration = this.GetService<IConfiguration>()
_configuration.ReloadDatabaseConfigurationProvider();
}
}
}
Database Schema
The provider stores configuration in a simple, flat table ConfigurationEntries structure:
| 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 |
Examples:
| 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 in ConfigurationEntries table are not detected by configuration provider. To apply changes made outside the application, you must restart the application or call ReloadDatabaseConfigurationProvider.
_configuration.ReloadDatabaseConfigurationProvider();
SQL Server
Maximum key length is 450 characters due to index limitations on NVARCHAR(450).
Concurrency
The library does not currently implement optimistic concurrency control or locking mechanisms. In multi-instance deployments:
- Last write wins
- Concurrent updates may overwrite each other
Performance Considerations
- Each update operation performs database I/O
- Read operations are cached by the configuration provider
Schema Management
- The table is auto-created on first use
- Schema migrations are not automatically handled
- Custom table names and column names are not yet configurable via public API
Null Handling
- Setting a value to
nullor empty string will delete the entry from the database - Arrays and enumerables set to
nullwill be removed entirely
Changelog
1.0.0
- first version
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 | 103 | 3/30/2026 |