JsonRepositoryConfiguration 1.0.0
dotnet add package JsonRepositoryConfiguration --version 1.0.0
NuGet\Install-Package JsonRepositoryConfiguration -Version 1.0.0
<PackageReference Include="JsonRepositoryConfiguration" Version="1.0.0" />
paket add JsonRepositoryConfiguration --version 1.0.0
#r "nuget: JsonRepositoryConfiguration, 1.0.0"
// Install JsonRepositoryConfiguration as a Cake Addin #addin nuget:?package=JsonRepositoryConfiguration&version=1.0.0 // Install JsonRepositoryConfiguration as a Cake Tool #tool nuget:?package=JsonRepositoryConfiguration&version=1.0.0
JsonRepositoryConfiguration
JsonRepositoryConfiguration is a ConfigurationProvider
based implementation which enables you to have your Repository as the refreshable source of your configuration.
It is very similar to Microsoft.Extensions.Configuration.Json. The only difference is that instead of using a appsettings.json file with AddJsonFile()
, you can use your own Repository with AddJsonRepository()
. Your JSON Repository can provide the data from any internal/external source(s) including SQL/NoSQL Database calls, API calls, etc. a JSON Repository implements IJsonConfigurationRepository
which only has GetByKey(string key)
method.
This package targets .NET Standard 2.0.
- Fully works with any mix of other Configuration Providers.
- Supports Refresh On Change.
- Overwrites configs that has been registered before it, and will be overwritten by those that has been registered after it (exactly like all other configuration providers in .NET).
- You still have all those good stuff like
IOptions<>
,IOptionsMonitor<>
,IOptionsSnapshot<>
etc.
Installing via NuGet
Install-Package JsonRepositoryConfiguration
Example
public class MyJsonRepository : IJsonConfigurationRepository
{
private readonly string _connectionString;
public MyJsonRepository(string connectionString)
{
_connectionString = connectionString;
}
public string Get(string key)
{
//Make some DB calls
return value;
/*
{
"myConfig": {
"cofnig1": "someString",
"config2": 5,
"config3": true
}
}
*/
}
}
// Optionaly add your appsettings files as usual:
builder.AddJsonFile($"appsettings.{env.EnvironmentName}.json");
// Add the JSON Repository
// Assuming this has been set in the previous line.
var connectionString = builder.Build().GetSection("ConnectionStrings:MyConnectionString").Value;
builder.AddJsonRepository("appsettings.NZ.json", new MyJsonRepository(connectionString), optional: false, reloadOnChange: true, changeCheckInterval: 20);
Important: To enable Reload On Change feature you MUST also register needed services as following:
public void ConfigureServices(IServiceCollection services){
// Registering needed services for Reload On Change feature:
services.AddJsonRepositoryReloadOnChange(Configuration);
// Binding:
services.Configure<MyConfig>(Configuration.GetSection("MyConfig"));
}
Note: The return string from your JSON Repository must be a valid JSON string (serialized/stringified) starting with "{". Exactly like appsettings.json.
Note: You can provide all your appsettings or only parts of it. This is the same as what you can do with appsettings.json and appsettings.development.json.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Configuration (>= 6.0.1)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 6.0.0)
- Microsoft.Extensions.Primitives (>= 6.0.0)
- System.Text.Json (>= 6.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Increase code readablility.