Dalisama.Extensions.Configuration
1.0.0
dotnet add package Dalisama.Extensions.Configuration --version 1.0.0
NuGet\Install-Package Dalisama.Extensions.Configuration -Version 1.0.0
<PackageReference Include="Dalisama.Extensions.Configuration" Version="1.0.0" />
paket add Dalisama.Extensions.Configuration --version 1.0.0
#r "nuget: Dalisama.Extensions.Configuration, 1.0.0"
// Install Dalisama.Extensions.Configuration as a Cake Addin
#addin nuget:?package=Dalisama.Extensions.Configuration&version=1.0.0
// Install Dalisama.Extensions.Configuration as a Cake Tool
#tool nuget:?package=Dalisama.Extensions.Configuration&version=1.0.0
Welcome to my humble readme
In this Repo, I implement a simple custom configuration provider that enable you to deliver and update your configuration via a Get api. When you have a microservice architecture and you need to update and change configuration, it is a tedious work, you need to restart and update every microservices. With tis NuGet, you only need to expose an APi that feed configuration to your service, and Voilà, you will be able to update your configuration in real time without the need of restarting anything. This NuGet will support the use of Consul and any API that provide you config via Get, it supports all type of authentication, because simply you will need to provide your httpClient, so +1 for flexibility.
Lead by Example
Let me walk you through the first example:
Let’s first download this repository locally and you will need the dotnetcore runtime duh! After that in the solution directory run this cmd:
dotnet build
now you need to open two command line in the following directory:
- \Dalisama.Extensions.Configuration.Api: this application will be providing the configuration via an api
- \Dalisama.Extensions.Configuration.Consumer: this application will be getting his configuration from the previous application
So you need to run this command in both command-lines:
dotnet run
from you brower, try to access this link: https://localhost:5005/confconsumer and you will get this json:
[
{
"element1": 360,
"element2": 454,
"element3": 545,
"element4": 1606
},
{
"element1": 232,
"element2": 1202,
"element3": 757,
"element4": 755
}
]
You will notice if you refresh the link in the browser, the first element in this array will be changed but the last one will be the same, because actually it's the same object but when it's resolved with IOptionsSnapshot, the framework will fetch the last value, so here you get the flexibility of knowing the first value or the updated one.
[HttpGet]
public List<ClassOption> Get([FromServices] IOptionsSnapshot<ClassOption> option1, [FromServices] IOptions<ClassOption> option2)
{
return new List<ClassOption> { option1.Value, option2.Value};
}
To get this result all you have to do is adding the nuget: Dalisama.Extensions.Configuration and updating your startup.cs:
public Startup(IConfiguration configuration)
{
Configuration = configuration;
Configuration = (IConfiguration)new ConfigurationBuilder().AddApiConfiguration(options =>
{
options.Url = "https://localhost:5001/ConfigurationProvider";
options.ReloadOnChange = true;
options.HttpClientFactory = () =>
{
var handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback = (request, cert, chain, errors) =>
{
return errors == SslPolicyErrors.None;
};
return new HttpClient(handler);
};
options.ConfigKeyFormatter = (key, value) => key;
options.ConfigValueFormatter = (key, value) => value;
}).Build();
}
and here in the ConfigureServices:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.Configure<ClassOption>(Configuration.GetSection("Section1"));
}
and Voilà!!!
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 (>= 3.1.6)
- Newtonsoft.Json (>= 12.0.3)
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 | 473 | 8/30/2020 |
0.0.2-alpha-08142020 | 314 | 8/14/2020 |
0.0.1-alpha-08142020 | 321 | 8/14/2020 |