Compentio.SourceConfig 1.0.3

There is a newer version of this package available.
See the version list below for details.
dotnet add package Compentio.SourceConfig --version 1.0.3
NuGet\Install-Package Compentio.SourceConfig -Version 1.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Compentio.SourceConfig" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Compentio.SourceConfig --version 1.0.3
#r "nuget: Compentio.SourceConfig, 1.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Compentio.SourceConfig as a Cake Addin
#addin nuget:?package=Compentio.SourceConfig&version=1.0.3

// Install Compentio.SourceConfig as a Cake Tool
#tool nuget:?package=Compentio.SourceConfig&version=1.0.3

SourceConfig

Introduction

SourceConfig is a code generator for objects that buit using *.json configuration files: when developer adds some file or new properties to existng json configuration file the POCO objects for this configuration generated.

It is based on Source Generators feature that has been intoduced with C# 9.0 and brings a possibility to generate code during build time.

How to use

During creation of any *json file (any json files are treated as configuration files), e.g. apsetting.json the POCO representation of this json is generated:

{
  "NoteEmailAddresses": [
    "admin@test.com",
    "technical.admin@test.com",
    "business.admin@test.com"
  ],
  "ConnectionTimeout": "30",
  "ConnectionHost": "https://test.com",
  "DefaultNote": {
    "Title": "DefaultTitle",
    "Description":  "DefaultDescription"
  }
}

in that case SourceConfig generates

// <mapper-source-generated />
// <generated-at '18.10.2021 14:49:51' />
using System;
using System.Collections.Generic;

namespace Compentio.SourceConfig.App
{
    public class AppSettings
    {
        public IEnumerable<string> NoteEmailAddresses { get; set; }

        public string ConnectionTimeout { get; set; }

        public string ConnectionHost { get; set; }

        public string DatabaseSize { get; set; }

        public DefaultNote DefaultNote { get; set; }
    }

    public class DefaultNote
    {
        public string Title { get; set; }

        public string Description { get; set; }
    }
}

AppSettings is taken from the filename, Compentio.SourceConfig.App namespace is inherited configuration file directory (here, appsettings.json is in app root directory, thus main app namespace is used).

If there are few appsettings files used for different environments, e.g. appsettings.development.json or appsettings.production.json they are merged into one generated class. Merge is based on first prefix in filename - here appsettings.

Now generated class can be used to retreive the configuration:

var appSettings = _configuration.Get<AppSettings>();

and should be earlier added to container:

static IHostBuilder CreateHostBuilder(string[] args)
{
    var configuration = new ConfigurationBuilder()
       .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
       .AddEnvironmentVariables()
       .Build();

    return Host.CreateDefaultBuilder(args)
        .ConfigureServices((_, services) =>
            services
            .Configure<AppSettings>(configuration)
            .AddTransient<INotesService, NotesService>());
}
Product 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. 
.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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.14 851 11/9/2021
1.0.10 692 10/19/2021
1.0.9 675 10/19/2021
1.0.8 639 10/19/2021
1.0.7 632 10/19/2021
1.0.5 642 10/19/2021
1.0.4 612 10/19/2021
1.0.3 658 10/19/2021