Skip to content

feat: code-first defaults initialization - #192

Merged
glucaci merged 2 commits into
mainfrom
fix-norestore-codefirst
Sep 18, 2026
Merged

glucaci merged 2 commits into
mainfrom
fix-norestore-codefirst

Conversation

@glucaci

@glucaci glucaci commented Sep 18, 2026

Copy link
Copy Markdown
Member

This pull request introduces support for "code-first" (contract-based) configuration schema derivation and validation for .NET projects. It adds new infrastructure for building, running, and extracting schemas from host projects, and integrates this workflow into the validation and scaffolding pipelines. The changes ensure that projects using option contracts (instead of component-based schemas) can benefit from the same tooling as traditional projects, including schema-based defaults and IDE integration.

The most important changes are:

Code-first schema derivation and validation:

  • Added DotnetOptionsRunner and DotnetOptionsSchemaComposer classes to build the host project, invoke the validation runner, and extract the JSON schema from option contracts. This enables dynamic schema generation for code-first projects. [1] [2]
  • Updated DotnetOptionsValidator to use the new runner and schema composer infrastructure, removing redundant build and runner logic from the validator.

Pipeline and middleware integration:

  • Registered the new RestoreDotnetSchemaMiddleware in the DI container and pipeline, ensuring that schema scaffolding and validation for code-first projects use the derived schema. [1] [2]
  • Modified RestoreProjectMiddleware to detect code-first projects and compose/store their schemas using the new infrastructure, bypassing the component-based schema logic when appropriate.

Schema export enhancements:

  • Enhanced SchemaExport to surface property initializers as schema defaults, allowing scaffolding tools to generate configuration files with real default values. This includes caching type instances and extracting default values only when they differ from CLR defaults. [1] [2] [3]

Validation runner improvements:

  • Changed the runner invocation logic so that schema export can occur even if the configuration document is invalid, enabling schema extraction before validation passes.

Dependency and usings updates:

  • Added necessary using statements for new types and features introduced in the code-first validation workflow. [1] [2]

These changes collectively enable robust support for contract-based configuration in .NET projects, aligning the developer experience for both code-first and component-based approaches.

@glucaci
glucaci merged commit a8b1d89 into main Sep 18, 2026
4 checks passed
@glucaci
glucaci deleted the fix-norestore-codefirst branch September 18, 2026 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant