Mindfire.SettingsConfiguration
1.0.0
This functionality is provided in the default .NET Standard 2.0 and above project versions
See the version list below for details.
dotnet add package Mindfire.SettingsConfiguration --version 1.0.0
NuGet\Install-Package Mindfire.SettingsConfiguration -Version 1.0.0
<PackageReference Include="Mindfire.SettingsConfiguration" Version="1.0.0" />
paket add Mindfire.SettingsConfiguration --version 1.0.0
#r "nuget: Mindfire.SettingsConfiguration, 1.0.0"
// Install Mindfire.SettingsConfiguration as a Cake Addin #addin nuget:?package=Mindfire.SettingsConfiguration&version=1.0.0 // Install Mindfire.SettingsConfiguration as a Cake Tool #tool nuget:?package=Mindfire.SettingsConfiguration&version=1.0.0
Mindfire Settings Reader
This project is meant to be a simple way of reading settings for an app in all project types that support .NET Standard. It provides a way of having a consistent settings experience across all projects and solutions.
Obtaining an Instance
The SettingsReader concrete class can be created for any other class that uses it, but the best way to use this reader is through dependency injection. Simply register the interface with the DI container and have it provide the concrete class.
container.RegisterSingleton<IReadSettings, SettingsReader>();
Then, any class that needs the settings reader may simply ask for it.
public MyClass(IReadSettings settingsReader) { this.SettingsReader = settingsReader; }
You may also register the IBindSettings
interface in order to bind settings classes to the data you seek.
Usage
Simple Settings
There are a couple of ways to use the reader, both based on which interface is being used. Reading simple settings out of the reader can be done by giving a key and specifying the value type (note: these must be primitive types).
ISettingsReader.Get<string>("MySettings");
If sectioned values are needed, each section can be separated by a semicolon until the value you want read.
ISettingsReader.Get<int>("Services:InventoryService:port");
Complex Settings
You can also retrieve all settings for a section by using the IBindSettings
interface. Provide a type that has the properties you want read, and the settings reader will attempt to fill the object.<br />
public class User {
public string Username { get; set; }
public int Id { get; set; }
}
var user = new User();
IBindSettings.Bind(user);
Connection Strings
By default, all settings from an app.config file are read from the appSettings
element. However, you can read from the connectionStrings
section by prepending the section name with ConnectionStrings:
like so
ISettingsReader.Get<string>("ConnectionStrings:MyDbConnection");
See unit tests for more examples.
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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.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 (>= 2.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 2.0.0)
- Microsoft.Extensions.Configuration.CommandLine (>= 2.0.0)
- Microsoft.Extensions.Configuration.EnvironmentVariables (>= 2.0.0)
- Microsoft.Extensions.Configuration.Json (>= 2.0.0)
- Microsoft.Extensions.Configuration.Xml (>= 2.0.0)
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 | |
---|---|---|---|
2.0.1 | 744 | 6/25/2020 | |
2.0.0 | 717 | 3/25/2019 | |
1.1.0 | 1,283 | 6/21/2018 | |
1.0.0 | 1,426 | 4/20/2018 | |
1.0.0-beta | 999 | 12/20/2017 |
Added ability to read from ConnectionStrings in an app.config