JsonRepositoryConfiguration 0.9.9

There is a newer version of this package available.
See the version list below for details.
dotnet add package JsonRepositoryConfiguration --version 0.9.9
NuGet\Install-Package JsonRepositoryConfiguration -Version 0.9.9
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="JsonRepositoryConfiguration" Version="0.9.9" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add JsonRepositoryConfiguration --version 0.9.9
#r "nuget: JsonRepositoryConfiguration, 0.9.9"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install JsonRepositoryConfiguration as a Cake Addin
#addin nuget:?package=JsonRepositoryConfiguration&version=0.9.9

// Install JsonRepositoryConfiguration as a Cake Tool
#tool nuget:?package=JsonRepositoryConfiguration&version=0.9.9

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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 2,029 9/26/2022
0.9.9 453 7/4/2022
0.9.8 424 7/4/2022
0.9.7 417 7/4/2022
0.9.6 405 6/14/2022
0.9.5 405 6/12/2022
0.9.4 388 6/12/2022
0.9.3 408 6/9/2022
0.9.2 418 6/9/2022
0.9.1 399 6/8/2022
0.9.0 418 6/8/2022

Increase code readablility.