TGC.Configuration 1.1.1

dotnet add package TGC.Configuration --version 1.1.1
NuGet\Install-Package TGC.Configuration -Version 1.1.1
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="TGC.Configuration" Version="1.1.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TGC.Configuration --version 1.1.1
#r "nuget: TGC.Configuration, 1.1.1"
#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 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.

Version Downloads Last updated
1.1.1 420 5/29/2023
1.1.0 107 5/29/2023
1.0.0 759 4/23/2023