https://github.com/thijstijsma/writableconfiguration.json
Store settings that are configured at runtime.
https://github.com/thijstijsma/writableconfiguration.json
configuration csharp json netstandard
Last synced: 5 months ago
JSON representation
Store settings that are configured at runtime.
- Host: GitHub
- URL: https://github.com/thijstijsma/writableconfiguration.json
- Owner: thijstijsma
- License: mit
- Created: 2018-12-15T17:41:35.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-06-23T18:51:55.000Z (about 4 years ago)
- Last Synced: 2025-11-07T06:24:07.720Z (8 months ago)
- Topics: configuration, csharp, json, netstandard
- Language: C#
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# WritableConfiguration.Json
Store settings that are configured at runtime.
You can specify the name of the configuration section and the file you want to use (default is "appsettings.json").
Note that when you use a custom file you have to add that manually to the `ConfigurationBuilder`.
## Installation
Reference the [ThijsTijsma.WritableConfiguration.Json](https://www.nuget.org/packages/ThijsTijsma.WritableConfiguration.Json/) NuGet package.
## Usage
~~~~csharp
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services.AddWritableJsonConfiguration(configuration.GetSection("Example"), "example.json");
}
}
public class SetupController : Controller
{
private readonly IWritableOptions _exampleSettings;
public SetupController(IWritableOptions exampleSettings)
{
_exampleSettings = exampleSettings;
});
[HttpPost]
public IActionResult SaveConnectionString([FromBody] string connectionString)
{
_exampleSettings.Value.ConnectionString = connectionString;
_exampleSettings.Write();
return View();
}
}
~~~~
### Output
~~~~json
{
"Example":
{
"ConnectionString": "Server=localhost"
}
}
~~~~
## Credits
Inspired by StackOverflow answers from [Matze](https://stackoverflow.com/a/42705862/) and [ceferrari](https://stackoverflow.com/a/45986656/).