TGC.Configuration
1.1.1
dotnet add package TGC.Configuration --version 1.1.1
NuGet\Install-Package TGC.Configuration -Version 1.1.1
<PackageReference Include="TGC.Configuration" Version="1.1.1" />
paket add TGC.Configuration --version 1.1.1
#r "nuget: TGC.Configuration, 1.1.1"
// Install TGC.Configuration as a Cake Addin #addin nuget:?package=TGC.Configuration&version=1.1.1 // Install TGC.Configuration as a Cake Tool #tool nuget:?package=TGC.Configuration&version=1.1.1
TGC.CSharpCodingStandards
This NuGet package is the personal C# coding standards for packages associated with TGC.Framework developed by Asger Thyregod.
Usage
This package wraps Microsoft.Extensions.Configuration and eases the consumption of configuration through a shared interface.
To use this package, you simply need to use on your service collection:
builder.Services.AddAppSettingsAbstraction();
This will automatically read environment variables, appsettings.json and local.settings.json (assuming they are located in your root directory). These will be injected into IAppSettings which can be used as a dependency injection in any service needed.
namespace Your.Namespace;
public class Service
{
private readonly IAppSettings _appSettings;
public Service(IAppSettings appSettings)
{
_appSettings = appSettings;
}
public void DoStuff()
{
var configurationValue = _appSettings.GetString("My:Key"); // Returns the value for { "My":{ "Key": "SomeKeyValue"} } (SomeKeyValue).
}
}
The IAppSettings allows for retrieval of configuration values as strings, bool, integers, doubles and typed:
namespace Your.Namespace;
public class Service
{
private readonly IAppSettings _appSettings;
public Service(IAppSettings appSettings)
{
_appSettings = appSettings;
}
public void DoStuff()
{
var stringValue = _appSettings.GetString("My:string");
var boolValue = _appSettings.GetString("My:bool");
var intValue = _appSettings.GetString("My:int");
var doubleValue = _appSettings.GetString("My:double");
}
public T GetTypedConfiguration(string? key) where T : class
{
// You can either retrieve a typed configuration from root via:
T someType = _appSettings.GetTyped<T>();
// Or if it is a sub-section you can also define the key path like:
T sameType = _appSettings.GetTyped<T>(key);
}
}
Changelog
1.0.0
First version ready to be consumed by other packages
1.1.0
Automatically reading appsettings.json and local.settings.json. Now possible to define a list of additional json files to read into IAppSettings as well. Also updated unit tests.
1.1.1
Fixed unused using and updated documentation.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. 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. |
-
net6.0
- Microsoft.Extensions.Configuration (>= 7.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 7.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 7.0.0)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 7.0.0)
- Microsoft.Extensions.Configuration.Json (>= 7.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 7.0.0)
- TGC.CSharpCodingStandards (>= 1.0.3)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on TGC.Configuration:
Package | Downloads |
---|---|
TGC.EFCoreRepositories
Wrapper and abstraction layer on-top of EntityFrameworkCore |
GitHub repositories
This package is not used by any popular GitHub repositories.