| Principle | C# Implementation | Tooling |
|---|---|---|
| Structural Separation | OpenAPI contracts + interface definitions | Microsoft.AspNetCore.OpenApi, TypeSpec |
| Generative Conformance | Source Generators (compile-time code generation) | Roslyn Generator API |
| Skeleton–Tissue Separation | Partial classes + template methods + DI | C# partial classes, sealed methods |
| Validation Gates | Roslyn analyzers + architecture tests | NetArchTest, ArchUnitNET |
| Recursive Refinement | Incremental builds + Git worktrees + assembly verification | Incrementalist, ApiCompatValidateAssemblies |
| Fixed Premise | Git tags + contract assemblies + specification files | Git, Microsoft.DotNet.ApiCompat |
| Inferential Density | record, init, required members |
C# 9–12 language features |
| Layer | Recommendation |
|---|---|
| Framework | .NET 9+ (OpenAPI built-in, incremental source generators) |
| Build | MSBuild + Incrementalist (Git-based impact analysis) |
| Specification | OpenAPI YAML / TypeSpec / JSON Schema |
| Code Generation | Source Generators (Roslyn), OpenAPI Generator |
| Static Validation | Roslyn analyzers (custom + built-in) |
| Architecture Testing | NetArchTest.eNhancedEdition |
| Module System | Namespace conventions (JPMS optional) |
| CI/CD | GitHub Actions / Azure DevOps + conditional gates |
Define all public API contracts in machine-readable format.
# openapi.yaml
openapi: 3.0.3
paths:
/api/players/{id}:
get:
operationId: GetPlayer
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/Player'
Define data structures separately from behavior.
// player-schema.json
{
"type": "object",
"required": ["id", "name"],
"properties": {
"id": { "type": "string" },
"name": { "type": "string" },
"score": { "type": "integer" }
}
}
Define behavior contracts using C# type system.
public interface IPlayerRepository
{
Task<Player> GetByIdAsync(string id, CancellationToken token);
Task UpdateAsync(Player player, CancellationToken token);
}
Implement incremental source generators for specification-to-code transformation.
[Generator]
public class SkeletonGenerator : IIncrementalGenerator
{
public void Initialize(IncrementalGeneratorInitializationContext context)
{
var provider = context.SyntaxProvider
.CreateSyntaxProvider(predicate: static (s, _) => IsTargetInterface(s),
transform: static (ctx, _) => GetInterfaceSymbol(ctx))
.Where(static m => m is not null);
context.RegisterSourceOutput(provider, GenerateSkeletonClass);
}
}
Configure generation in .csproj:
<PropertyGroup>
<EmitCompilerGeneratedFiles>true</EmitCompilerGeneratedFiles>
<CompilerGeneratedFilesOutputPath>$(BaseIntermediateOutputPath)Generated</CompilerGeneratedFilesOutputPath>
</PropertyGroup>
Template method pattern with sealed orchestration methods.
public abstract class ServiceSkeleton : IService
{
public sealed async Task<Result> ExecuteAsync(Request req)
{
await OnBeforeExecute(req);
var result = await ExecuteCoreAsync(req);
await OnAfterExecute(result);
return result;
}
protected abstract Task<Result> ExecuteCoreAsync(Request req);
protected virtual Task OnBeforeExecute(Request req) => Task.CompletedTask;
protected virtual Task OnAfterExecute(Result res) => Task.CompletedTask;
}
Concrete implementations generated from specification.
// Auto-generated from OpenAPI/JSON Schema
public partial class PlayerService : ServiceSkeleton, IPlayerService
{
private readonly IPlayerRepository _repository;
public partial PlayerService(IPlayerRepository repository)
{
_repository = repository;
}
protected override async Task<Result> ExecuteCoreAsync(Request req)
{
// Generated business logic
}
}
// Manual extension - not regenerated
public partial class PlayerService
{
partial void OnConstructed()
{
Logger.LogInformation("Service initialized");
}
protected override async Task OnAfterExecute(Result res)
{
await PublishEventAsync(res);
}
}
Enforce tissue layer constraints at compilation.
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public class TissueConformanceAnalyzer : DiagnosticAnalyzer
{
// Rule: Generated types must implement skeleton interfaces
}
Enforce layer dependencies in unit tests.
[Fact]
public void Tissue_Should_Only_Depend_On_Skeleton()
{
var rule = Types().That().ResideInNamespace("Tissue")
.Should().OnlyDependOn(Types().That().ResideInNamespace("Skeleton"));
rule.Check(Architecture);
}
Snapshot-test generated outputs.
[Fact]
public Task Generator_Produces_Correct_Skeleton()
{
var test = new CSharpSourceGeneratorTest<MyGenerator>
{
TestCode = InputSource,
ExpectedDiagnostics = { }
};
test.TestState.GeneratedSources.Add(ExpectedOutput);
return test.RunAsync();
}
Phase N complete
│
├── Git tag: phase-N-complete
├── Save contract assembly as baseline (ApiCompat)
│
▼
Modify structural specification (OpenAPI / JSON Schema)
│
├── Incrementalist detects affected projects
├── Incremental source generator runs only on changed inputs
│
▼
Validation gates
│
├── Roslyn analyzers (compile-time)
├── NetArchTest (unit test)
├── ApiCompat (assembly compatibility)
│
▼
Phase N+1 complete
│
└── Git tag: phase-N+1-complete
git worktree add ../project-phase2 phase2-branch
git worktree add ../project-phase3 phase3-branch
<Target Name="GenerateFromSpec"
Inputs="@(OpenApiSpec)"
Outputs="@(GeneratedCode)">
<OpenApiGenerator Inputs="@(OpenApiSpec)" Outputs="@(GeneratedCode)"/>
</Target>
name: Deep Coding Validation
on: [push, pull_request]
jobs:
validate:
steps:
- name: Impact analysis
run: incrementalist run -b main -- build --no-incremental
- name: Architecture tests
run: dotnet test --filter "Category=Architecture"
- name: Generator tests
run: dotnet test --filter "Category=GeneratorTest"
- name: API compatibility
run: dotnet build -p:ApiCompatValidateAssemblies=true
- name: Verify generated code is committed
run: git diff --exit-code -- '**/*.g.cs'
if (await featureManager.IsEnabledAsync("NewFeature"))
{
return await newImplementation.ExecuteAsync();
}
return await legacyImplementation.ExecuteAsync();
| Phase | Scope | Deliverable |
|---|---|---|
| 0 | Infrastructure | .NET 9 SDK, Git worktree training, NetArchTest in CI |
| 1 | API contracts | OpenAPI/TypeSpec definitions + generated interfaces |
| 2 | Data contracts | JSON Schema + generated POCOs with JsonSchema.Net |
| 3 | Business logic (optional) | Skeleton abstract classes + generated tissue stubs |
| 4 | Governance | Weekly drift detection, compatibility reports |
| Constraint | Mitigation |
|---|---|
| Reflection-heavy libraries (EF Core, Newtonsoft.Json) | Apply Deep Coding only to contract layer. Internal implementation uses traditional patterns. |
| Partial classes do not work with structs | Use DI + abstract factory for performance-critical areas. |
| Generated code debugging difficulty | Enable EmitCompilerGeneratedFiles, use source link. |
| Unity runtime differences | Apply Deep Coding only to ECS layer. Keep asset pipeline separate. |
| Build time in large monorepos | Incrementalist + incremental source generators reduce to practical levels. |
C# and .NET provide all necessary language features and tooling to implement Deep Coding methodology. The stack—OpenAPI for contracts, source generators for conformance, partial classes for skeleton-tissue separation, Roslyn analyzers and NetArchTest for validation, and Incrementalist plus Git worktrees for recursive refinement—forms a complete, production-ready foundation. ASP.NET Core projects achieve full compatibility; game development (MonoGame, Unity) achieves partial but valuable applicability. Following the phased implementation plan minimizes risk while delivering measurable ROI within months. ```