Skip to content

Latest commit

 

History

History
26 lines (17 loc) · 1.21 KB

README.md

File metadata and controls

26 lines (17 loc) · 1.21 KB

Source Generator for generating POCO classes based on your appsettings.json files

NuGet Badge

This Source Generator generates POCO's based on your appsettings.json files. It also supports multiple settings files: appsettings.json + appsettings.Development.json + appsettings.Production.json, etc.

  1. Add the appsettings.json files to your .csproj like this:
  <ItemGroup>
    <AdditionalFiles Include="appsettings.json" />
    <AdditionalFiles Include="appsettings.Development.json" />
  </ItemGroup>

You can add as many appsettings files as you want :)

  1. The config classes are generated in the namespace ApplicationConfig (This will be configurable in the next release).
  2. Register your config in the DI container: builder.Services.Configure<ApplicationConfig.MyAppConfig>(builder.Configuration);
  3. Inject the config in your constructor: IOptions<ApplicationConfig.MyAppConfig> options

⚠️ You may have to restart Visual Studio after installing this NuGet package!

See this blogpost for more information:

https://albertromkes.com/2020/11/04/a-source-generator-for-your-appsettings-json/