Compentio.SourceConfig
1.0.3
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
<PackageReference Include="Compentio.SourceConfig" Version="1.0.3" />
paket add Compentio.SourceConfig --version 1.0.3
#r "nuget: Compentio.SourceConfig, 1.0.3"
// 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 | Versions 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. |
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 3.11.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.