IOptionsWriter
Easy way to write appsettings.json or other configuration json file
Install / Use
/learn @ch1seL/IOptionsWriterREADME
IOptionsWriter
Easy way to write appsettings.json or other configuration json file
How to use
Installation
Nuget Package Manager Console:
Install-Package IOptionsWriter
.Net CLI:
dotnet add package IOptionsWriter
Using
IServiceCollection.ConfigureWritable<TOptions>(string sectionName = null, string settingsFile = "appsettings.json", bool reloadAfterWrite = false)
TOptions - type of your settings
sectionName - your configuration section name(default: TOptions type name)
settingsFile - default appsettings.json
reloadAfterWrite - you can enable this option if you have problems detecting file changes or if add the settings file with false value of reloadOnChange parameter (builder.AddJsonFile(appsettings.json, optional: false, reloadOnChange: false);)
Simple sample
appsettings.json:
{
"MySettings": {
"MyOption": "MyValue"
}
}
Startup.cs:
public void ConfigureServices(IServiceCollection services)
{
services
.AddOptions()
.ConfigureWritable<MySettings>();
}
Controllers/MyController.cs:
[Controller]
public class MyController : Controller {
private readonly IOptionsWritable<MySettings> _myOptionsAccessor;
public MyController(IOptionsWritable<MySettings> myOptionsAccessor) {
_myOptionsAccessor = myOptionsAccessor;
}
[HttpPut]
public IActionResult SetMyOptionValue(string value) {
_myOptionsAccessor.Update(options => options.MyOption = value);
}
}
Related Skills
node-connect
347.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
107.8kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.0kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
