MutableConfig 1.0.2
See the version list below for details.
dotnet add package MutableConfig --version 1.0.2
NuGet\Install-Package MutableConfig -Version 1.0.2
<PackageReference Include="MutableConfig" Version="1.0.2" />
<PackageVersion Include="MutableConfig" Version="1.0.2" />
<PackageReference Include="MutableConfig" />
paket add MutableConfig --version 1.0.2
#r "nuget: MutableConfig, 1.0.2"
#:package MutableConfig@1.0.2
#addin nuget:?package=MutableConfig&version=1.0.2
#tool nuget:?package=MutableConfig&version=1.0.2
MutableConfig
A lightweight and extensible .NET/C# library for runtime configuration management, supporting type-safe mapping of C# classes to JSON files.
About
MutableConfig is a configuration management library for the .NET/C# environment. It is designed to allow applications to easily load, modify, and persist configuration items at runtime without needing to restart or redeploy. It supports organizing configurations into a hierarchical structure, dynamic updates, and is designed to be lightweight and extensible.
Common use cases include:
ð Runtime Configuration Updates: When you have an application and need to change certain configuration items during runtime without stopping the application.
ð§Đ C# to JSON Mapping: Map C# types to JSON files one by one, enabling strong-typed configuration access.
ð Centralized Multi-Module Management: Want to centrally manage configurations across multiple modules/environments and support features like hot updates.
Key Features
Here are some of the key features of this library:
âïļ Runtime Mutable Configuration: Supports easily modifying configuration items with code during the application's runtime without needing to restart the application.
ð§Đ Configuration File Hierarchy and Typed Access:
- Maps C# classes to JSON files one-to-one, providing strong-typed access.
- Configuration fields can be read and modified like regular C# objects.
- Changes are persisted to the JSON file explicitly via the
SaveChanges()method, keeping the file hierarchy consistent with the type definitions.
ðū Persistence and Recovery Mechanism: Configuration changes can be saved persistently, allowing the previous state to be restored on the next startup.
ðŠķ Lightweight: Uses only core .NET features without relying on many external libraries, making it easy to embed and extend.
How to Use
Installation
dotnet add package MutableConfig
Add to Program.cs:
using MutableConfig;
// Configuration Data Preparation
const string configFolderName = "Config";
var basePath = Path.Join(AppContext.BaseDirectory, configFolderName);
var defaultAppSettingsConfig = new AppSettingsConfig {
AppName = "MutableConfig Sample App", Version = "1.0.0", EnableDebug = true
};
var defaultDatabaseConfig = new DatabaseConfig {
Host = "localhost", Port = 5432
};
/*
* Dependency Injection
*
* AppSettingsConfig is a custom configuration class.
* Once registered through dependency injection, MutableConfig will ensure that
* an "AppSettingsConfig.json" file exists under the specified basePath.
*
* On the first run, if the configuration file does not exist, it will be created
* using the default values provided through SetupDefaultConfigIfNotExists().
*
* Configuration objects are fully mutable at runtime, and changes made to them
* are tracked within their corresponding ConfigContext<T>. To persist updates
* to the underlying JSON file, you explicitly call SaveChanges() on the context.
*/
builder.Services.AddConfigContext<AppSettingsConfig>(opt =>
opt.SetBasePath(basePath)
.SetupDefaultConfigIfNotExists(defaultAppSettingsConfig));
Example
You can find a complete working example here:
ð Sample Code
This sample demonstrates how to define a configuration class, bind it to a JSON file, and modify it at runtime while keeping both sides synchronized.
Main Types
The main types provided by this library are:
ConfigContext<T>â A configuration context for a specific type. UseConfigContext<T>for a particular configuration class.ConfigContextOptions<T>â Options for configuring aConfigContext<T>.
Feedback & Contributing
MutableConfig is released as open source under the Apache-2.0 license. Bug reports and contributions are welcome at the GitHub repository.
| 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. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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.DependencyInjection (>= 2.1.0)
- Newtonsoft.Json (>= 13.0.4)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.