Dalisama.Extensions.Configuration
0.0.1-alpha-08142020
See the version list below for details.
dotnet add package Dalisama.Extensions.Configuration --version 0.0.1-alpha-08142020
NuGet\Install-Package Dalisama.Extensions.Configuration -Version 0.0.1-alpha-08142020
<PackageReference Include="Dalisama.Extensions.Configuration" Version="0.0.1-alpha-08142020" />
paket add Dalisama.Extensions.Configuration --version 0.0.1-alpha-08142020
#r "nuget: Dalisama.Extensions.Configuration, 0.0.1-alpha-08142020"
// Install Dalisama.Extensions.Configuration as a Cake Addin
#addin nuget:?package=Dalisama.Extensions.Configuration&version=0.0.1-alpha-08142020&prerelease
// Install Dalisama.Extensions.Configuration as a Cake Tool
#tool nuget:?package=Dalisama.Extensions.Configuration&version=0.0.1-alpha-08142020&prerelease
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à!!!
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
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 |
Summary of changes made in this release of the package.