WritableJsonConfiguration 8.1.1
See the version list below for details.
dotnet add package WritableJsonConfiguration --version 8.1.1
NuGet\Install-Package WritableJsonConfiguration -Version 8.1.1
<PackageReference Include="WritableJsonConfiguration" Version="8.1.1" />
<PackageVersion Include="WritableJsonConfiguration" Version="8.1.1" />
<PackageReference Include="WritableJsonConfiguration" />
paket add WritableJsonConfiguration --version 8.1.1
#r "nuget: WritableJsonConfiguration, 8.1.1"
#:package WritableJsonConfiguration@8.1.1
#addin nuget:?package=WritableJsonConfiguration&version=8.1.1
#tool nuget:?package=WritableJsonConfiguration&version=8.1.1
WritableJsonConfiguration
<img src="https://github.com/Kibnet/WritableJsonConfiguration/raw/master/resources/JSON_logo.png" alt="JSON" width="180"/>
What is it?
If you want to add a settings to your app and you like json, then this is what you need. This uses the standard interface for working with settings, which is provided by Microsoft.Extensions.Configuration. To do this, we added methods for changing values in settings via the standard interface, which will edit the json file themselves.
How to use?
Add Nuget Package in your project:
Install-Package WritableJsonConfiguration
Create configuration:
IConfigurationRoot configuration = WritableJsonConfigurationFabric.Create("Settings.json");
Use this configuration in the app as you need, usually people register it with the IoC, example(Splat):
Locator.CurrentMutable.RegisterConstant(configuration, typeof(IConfiguration));
Get value:
Themes theme = configuration.GetSection("Appearance:Theme").Get<Themes>();
or
Themes theme = configuration.Get<Themes>("Appearance:Theme");
Set value:
configuration.GetSection("Appearance:Theme").Set(theme);
or
configuration.Set("Appearance:Theme", theme);
Opt-in atomic writes on Windows
IConfigurationRoot configuration = WritableJsonConfigurationFabric.Create(source =>
{
source.Path = "Settings.json";
source.Optional = true;
source.ReloadOnChange = false;
source.UseAtomicWrites = true;
source.ResolveFileProvider();
});
UseAtomicWrites defaults to false, preserving the previous API and platform behavior.
When enabled, both Set overloads serialize writes to the same physical path within
the process. A complete, parser-validated temporary file is flushed and replaces the
main file; .bak contains the previous readable version. A first save creates only
the main file. No-op saves do not rotate the backup. Memory is published after the
file commit; ambiguous I/O errors reread disk and block further writes if reconciliation
fails. Restart the application or recreate the configuration root before trying
again in that case; calling Reload() on the same root does not unblock writes.
Numeric path segments remain property names inside JSON objects. Inside arrays they
are indexes; sparse indexes are rejected rather than redirected to another element.
Temporary files receive the source file's restricted Windows access permissions
before any settings bytes are written. Existing main/backup permission differences
that cannot safely be preserved cause an error, not a broader copy. The first file
uses the containing directory's permissions. Other operating systems reject explicit
opt-in with PlatformNotSupportedException; the default mode remains available.
This does not recover an already corrupt file, coordinate multiple processes, make a
series of Set calls transactional, or guarantee survival of arbitrary hardware
failure. Applications should validate/recover settings before loading configuration.
Backups and leftover temporary files may contain secrets and must not be published.
Communication
Any suggestions and comments are welcome. If you want to contact me, use Telegram
| 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.CSharp (>= 4.7.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.1)
- Microsoft.Extensions.Configuration.Json (>= 8.0.0)
- Newtonsoft.Json (>= 13.0.3)
- System.IO.FileSystem.AccessControl (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on WritableJsonConfiguration:
| Repository | Stars |
|---|---|
|
SimpleStateMachine/SimpleStateMachineNodeEditor
🔗WPF node editor based on ReactiveUI
|
Fix atomic-path handling for numeric object keys and reject sparse array indexes instead of writing a different index.