app settings editor - powered by Roslyn
Autogenerates controller API for appsettings.json
Optional, it has also an endpoint for a HTML GUI editor
This is how swagger looks :
And you can browse to /settingsUI to have this editor ( powered by https://github.com/json-editor/json-editor )
Add 2 NUGET references:
appSettingEditorAPI appSettingsEditor
For your convenience, please add to the csproj :
<ItemGroup>
<PackageReference Include="appSettingsEditor" Version="2021.3.21.2300" />
<PackageReference Include="appSettingsEditorAPI" Version="2021.3.21.2300" />
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="generateAPI" />
<AdditionalFiles Include="appsettings.json" generateAPI="true" >
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</AdditionalFiles>
</ItemGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
If you want to see a GUI for settings ( /settingsUI) , please do
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers(); // add next line
endpoints.MapSettingsView <SettingsJson.appsettings>(Configuration);
});
If you want to handle security, add
public partial class appsettingsController : ControllerBase
{
//partial void BeforeGet(appsettings data)
//{
//}
//partial void BeforeSave(appsettings data, appsettings original)
//{
//}
}
Add this to Startup.cs ,
public void ConfigureServices(IServiceCollection services)
services.AddApiVersioning(
it =>
{
it.AssumeDefaultVersionWhenUnspecified = true;
it.DefaultApiVersion = new ApiVersion(1,0);
}
);
Make the modifications below: In the csproj
<ItemGroup>
<PackageReference Include="appSettingsEditor" Version="2021.3.21.2300" />
<PackageReference Include="appSettingsEditorAPI" Version="2021.3.21.2300" />
<CompilerVisibleItemMetadata Include="AdditionalFiles" MetadataName="generateAPI" />
<AdditionalFiles Include="app_custom_setting.json" generateAPI="true">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</AdditionalFiles>
</ItemGroup>
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
In the startup.cs
appSettingsEditor.Extensions.MapSettingsView<app_custom_setting>(endpoints, Configuration,"app_custom_setting.json","/api/app_custom_setting");
This is not supported yet for the GUI. Please make an issue and describe your problem