FractalDataWorks.Configuration.SourceGenerators 0.6.0-rc.1

This is a prerelease version of FractalDataWorks.Configuration.SourceGenerators.
dotnet add package FractalDataWorks.Configuration.SourceGenerators --version 0.6.0-rc.1
                    
NuGet\Install-Package FractalDataWorks.Configuration.SourceGenerators -Version 0.6.0-rc.1
                    
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="FractalDataWorks.Configuration.SourceGenerators" Version="0.6.0-rc.1">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FractalDataWorks.Configuration.SourceGenerators" Version="0.6.0-rc.1" />
                    
Directory.Packages.props
<PackageReference Include="FractalDataWorks.Configuration.SourceGenerators">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FractalDataWorks.Configuration.SourceGenerators --version 0.6.0-rc.1
                    
#r "nuget: FractalDataWorks.Configuration.SourceGenerators, 0.6.0-rc.1"
                    
#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.
#:package FractalDataWorks.Configuration.SourceGenerators@0.6.0-rc.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FractalDataWorks.Configuration.SourceGenerators&version=0.6.0-rc.1&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=FractalDataWorks.Configuration.SourceGenerators&version=0.6.0-rc.1&prerelease
                    
Install as a Cake Tool

FractalDataWorks.Configuration.SourceGenerators

Incremental source generator that creates DDL definitions, ConfigurationTypes collection, FluentValidation validators, and validation logging from [ManagedConfiguration] attributes.

Features

  • Embedded Attributes: No runtime dependency required - attributes are generated into your assembly
  • DDL Generation: Generates SQL Server DDL for configuration tables with parent/child relationships
  • ConfigurationTypes Collection: Compile-time discovery of all managed configurations
  • FluentValidation: Generates validators with TypeCollection reference validation
  • Validation Logging: Generates [MessageLogging] methods for validation error logging

Usage

From MsSqlConnectionConfiguration.cs:43-54:

[ManagedConfiguration(
    Schema = "cfg",
    TableName = "MsSqlConnection",
    Parent = nameof(ConnectionConfigurationBase<MsSqlConnectionConfiguration>),
    ServiceCategory = "Connection",
    ServiceType = "MsSql")]
public partial class MsSqlConnectionConfiguration : ConnectionConfigurationBase<MsSqlConnectionConfiguration>
{
    public override string ConnectionType => "MsSql";
    public string Server { get; set; } = "localhost";
    public string Database { get; set; } = string.Empty;
    public int Port { get; set; } = 1433;
}

Parent configurations define shared properties that child configurations inherit. The generator creates parent-child DDL relationships with foreign keys.

Generated Output

  • {ClassName}.Ddl.g.cs - DDL definition with table schema
  • {ClassName}.Validator.g.cs - FluentValidation validator
  • {ClassName}.ValidationLog.g.cs - Logging messages for validation
  • ConfigurationTypes.g.cs - Discovery collection with All(), ByName(), FromType<T>()
  • {TypeCollection}.TypeCollectionDdl.g.cs - DDL for TypeCollection lookup tables
  • TypeCollectionDdlRegistry.g.cs - Registry of TypeCollections requiring tables

Attributes

[ManagedConfiguration]

Marks a class as a managed configuration.

From ManagedConfigurationAttribute.cs (embedded source):

Property Description
Parent Parent configuration name for child relationships
Schema Database schema (default: "cfg")
TableName Override table name (default: class name without "Configuration" suffix)
DisplayName Display name for UI
Description Description for UI help text
ServiceCategory Service category (e.g., "Connection", "Workflow") - inferred from class name suffix if not set
ServiceType Service type (e.g., "MsSql", "Customer") - inferred from class name prefix if not set
GenerateDdl Generate DDL (default: true)
GenerateValidator Generate FluentValidation (default: true)
GenerateUi Generate UI form models (default: true)
OnDelete FK delete behavior: Cascade, SetNull, NoAction (default: "Cascade")
DatabaseProvider MsSql or PostgreSql (default: MsSql)

[ConfigurationOption]

Marks a property as referencing a TypeCollection. Generates FK from configuration table to TypeCollection table and validation rules.

From ConfigurationOptionAttribute.cs (embedded source):

Property Description
TypeCollection The TypeCollection type (constructor parameter)
ById Validate against ById() instead of ByName() (default: false)
TableName Override TypeCollection table name (default: TypeCollection name)
Schema Override TypeCollection table schema (default: "cfg")

[DbType]

Overrides the default SQL type mapping for a property.

From DbTypeAttribute.cs (embedded source):

Property Description
SqlType SQL type (constructor parameter) - e.g., "varchar", "nvarchar", "decimal"
MaxLength String/binary max length (default: -1, use type default)
Precision Decimal precision (default: -1, use type default)
Scale Decimal scale (default: -1, use type default)

TypeCollection DDL Generation

When a configuration property references a TypeCollection via [ConfigurationOption], the generator automatically creates DDL for the TypeCollection lookup table.

How It Works

  1. Generator Phase: When you add [ConfigurationOption(typeof(ConnectionStates))] to a property:

    • DDL is generated for the ConnectionStates lookup table (Id int PK, Name varchar unique)
    • FK is added from the configuration table to the TypeCollection table
    • A TypeCollectionDdlRegistry is generated listing all TypeCollections
  2. Bootstrap Phase: When the application starts, ConfigurationSchemaBootstrapService:

    • Creates TypeCollection tables if they don't exist
    • Seeds data by calling TypeCollection.All() and inserting each option
    • Creates configuration tables with FK constraints

Example

The [ConfigurationOption] attribute marks a property as referencing a TypeCollection. This generates a foreign key constraint from the configuration table to the TypeCollection lookup table.

// Illustrative example - [ConfigurationOption] creates FK to TypeCollection table
[ManagedConfiguration]
public class ConnectionMonitorConfiguration
{
    public Guid Id { get; set; }
    public string Name { get; set; } = string.Empty;

    // Creates FK: ConnectionMonitor.InitialState -> ConnectionStates.Name
    [ConfigurationOption(typeof(ConnectionStates))]
    public string InitialState { get; set; } = "Disconnected";

    // Creates FK: ConnectionMonitor.DefaultStateId -> ConnectionStates.Id
    [ConfigurationOption(typeof(ConnectionStates), ById = true)]
    public int DefaultStateId { get; set; } = 1;
}

The TypeCollection referenced above is defined in the codebase.

From ConnectionStates.cs:12-14:

[TypeCollection(typeof(ConnectionStateBase), typeof(IConnectionState), typeof(ConnectionStates))]
public abstract partial class ConnectionStates : TypeCollectionBase<ConnectionStateBase, IConnectionState>
{
}

Generated Database Schema

The generator produces DDL for both the TypeCollection lookup table and the configuration table with foreign key constraints:

-- TypeCollection table (created first)
CREATE TABLE cfg.ConnectionStates (
    Id int NOT NULL PRIMARY KEY,
    Name varchar(100) NOT NULL UNIQUE
);

-- TypeCollection data seeded from ConnectionStates.All()
INSERT INTO cfg.ConnectionStates (Id, Name) VALUES (1, 'Disconnected');
INSERT INTO cfg.ConnectionStates (Id, Name) VALUES (2, 'Connecting');
INSERT INTO cfg.ConnectionStates (Id, Name) VALUES (3, 'Connected');
-- ...

-- Configuration table with FKs
CREATE TABLE cfg.ConnectionMonitor (
    Id uniqueidentifier NOT NULL PRIMARY KEY,
    Name varchar(256) NOT NULL UNIQUE,
    InitialState varchar(100) NOT NULL,
    DefaultStateId int NOT NULL,
    CONSTRAINT FK_ConnectionMonitor_ConnectionStates FOREIGN KEY (InitialState) REFERENCES cfg.ConnectionStates(Name),
    CONSTRAINT FK_ConnectionMonitor_ConnectionStates_Id FOREIGN KEY (DefaultStateId) REFERENCES cfg.ConnectionStates(Id)
);

Idempotent Behavior

All operations are idempotent:

  • Tables are only created if they don't exist
  • Columns are only added if missing
  • TypeOption rows are only inserted if not present (checked by Id)
  • Safe to run multiple times

Installation

Reference this source generator in your project:

<ItemGroup>
  <ProjectReference Include="..\..\src\FractalDataWorks.Configuration.SourceGenerators\FractalDataWorks.Configuration.SourceGenerators.csproj"
                    OutputItemType="Analyzer"
                    ReferenceOutputAssembly="false" />
</ItemGroup>

The OutputItemType="Analyzer" and ReferenceOutputAssembly="false" attributes are required for source generator references.

Next Steps

There are no supported framework assets in this 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
0.6.0-rc.1 57 2/9/2026
Loading failed