ConfigurationRepository 1.1.0
See the version list below for details.
dotnet add package ConfigurationRepository --version 1.1.0
NuGet\Install-Package ConfigurationRepository -Version 1.1.0
<PackageReference Include="ConfigurationRepository" Version="1.1.0" />
<PackageVersion Include="ConfigurationRepository" Version="1.1.0" />
<PackageReference Include="ConfigurationRepository" />
paket add ConfigurationRepository --version 1.1.0
#r "nuget: ConfigurationRepository, 1.1.0"
#addin nuget:?package=ConfigurationRepository&version=1.1.0
#tool nuget:?package=ConfigurationRepository&version=1.1.0
ConfigurationRepository
An ASP .NET Core class library that provides access to application`s configuration stored in a database or any other repository.
Installation:
- from NuGet;
- from package manager console:
Install-Package ConfigurationRepository
- from command line:
dotnet add package ConfigurationRepository
Usage:
The configuration can be stored in two different structured forms, we have to choose one:
- A single configuration with it`s keys and values, like in a dictionary, this one called
DictionaryRepository
. - Multiple configurations, one of which is extracted using the
Key
and aValue
that contains parsable hierarchical structure of the configuration by thatKey
. This one calledParsableRepository
.
Currently, the only format supported for ParsableRepository
is in JSON
format. This can be easily extended implementing IConfigurationParser
interface for any format needed.
A dictionary repository provider is registered by calling AddDictionaryRepository()
extension method on configuration builder.
A parsable repository provider is registered by calling AddParsableRepository()
extension method on configuration builder.
Examples:
Here is a simple example with two in-memory repositories:
- A dictionary repository that stores it`s data as key-value pairs.
- A parsable repository that is stored as a string parsed into a JSON.
using ConfigurationRepository;
var builder = WebApplication.CreateBuilder(args);
// Define our sample data for dictionary repository.
var configDictData = new Dictionary<string, string?>(StringComparer.OrdinalIgnoreCase)
{ { "DICT KEY", "DICT VALUE" } };
// Define our sample data for json repository.
var configJsonData = """{"JSON KEY":"JSON VALUE"}""";
// Add our two configuration repository providers with different
// repositories to configuration builder.
builder.Configuration
.AddDictionaryRepository(new InMemoryDictionaryRepository(configDictData))
.AddParsableRepository(new InMemoryJsonRepository(configJsonData));
var app = builder.Build();
app.Run();
// A dictionary in-memory repository.
class InMemoryDictionaryRepository(IDictionary<string, string?> configData)
: IConfigurationRepository
{
public TData GetConfiguration<TData>()
{
return (TData)configData;
}
}
// A parsable json in-memory repository.
class InMemoryJsonRepository(string jsonConfig)
: IConfigurationRepository
{
public TData GetConfiguration<TData>()
{
return (TData)Convert.ChangeType(jsonConfig, typeof(TData));
}
}
More complex example with database-stored configuration repository that stores secrets separatley in Vault
and parametrizes this configuration with these secret values you may find in ConfigurationRepository.VaultWithDbWebApp sample project on github.
Note that It uses docker
and docker-compose
to set things up.
See also:
The main purpose of ConfigurationRepository
is to store the configuration in a database. The following libraries provide this:
Dapper configuration repository - for accessing a database configuration using Dapper ORM
EntityFramework configuration repository - for accessing a database configuration using Entity Frameworks ORM
SqlClient configuration repository - for accessing MS SQL Server database configuration using SqlClient library
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.Extensions.Configuration (>= 8.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- ReloadableConfiguration (>= 1.1.0)
NuGet packages (3)
Showing the top 3 NuGet packages that depend on ConfigurationRepository:
Package | Downloads |
---|---|
ConfigurationRepository.Dapper
Configuration repository provider that stored in a database and accessed via Dapper ORM. |
|
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. |
GitHub repositories
This package is not used by any popular GitHub repositories.