ConfigurationRepository 1.1.1
dotnet add package ConfigurationRepository --version 1.1.1
NuGet\Install-Package ConfigurationRepository -Version 1.1.1
<PackageReference Include="ConfigurationRepository" Version="1.1.1" />
<PackageVersion Include="ConfigurationRepository" Version="1.1.1" />
<PackageReference Include="ConfigurationRepository" />
paket add ConfigurationRepository --version 1.1.1
#r "nuget: ConfigurationRepository, 1.1.1"
#addin nuget:?package=ConfigurationRepository&version=1.1.1
#tool nuget:?package=ConfigurationRepository&version=1.1.1
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 type of configuration repository is called
Dictionary repository
. - Multiple configurations, one of which is extracted using the
Key
and aValue
that contains parsable hierarchical structure of the configuration by thatKey
. This type of configuration repository is calledParsable repository
.
Currently, the only format supported for Parsable repository
is in JSON
format. This can be easily extended implementing IConfigurationParser
interface for any format needed.
A dictionary repository provider is registered by AddDictionaryRepository()
extension method called on configuration builder.
A parsable repository provider is registered by AddParsableRepository()
extension method called 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 all environment up.
See also:
The main purpose of ConfigurationRepository
is to store the configuration in a database. The following libraries provide this:
ConfigurationRepository.Dapper - for accessing database configurations using Dapper ORM.
ConfigurationRepository.EntityFramework - for accessing database configurations using Entity Frameworks ORM.
ConfigurationRepository.SqlClient - for accessing MS SQL Server database configurations using MS SqlClient library.
Any of these configurations may also be parametrizable:
ParametrizedConfiguration - for parametrizing configuration provided by other configuration providers.
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.1)
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.