feat: add aggregate root pattern slice#408
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
There was a problem hiding this comment.
Pull request overview
Adds a new Domain Modeling “Aggregate Root” slice to PatternKit, spanning runtime APIs, a source generator, example/demo + DI integration, benchmark coverage, and production-readiness documentation/catalog updates (per #403).
Changes:
- Introduces
AggregateRoot<TId,TEvent>andAggregateCommandHandler<TAggregate,TCommand,TEvent>runtime APIs with TinyBDD coverage. - Adds aggregate command handler source generator + abstractions attributes, plus generator diagnostics/tests and analyzer release notes.
- Adds an importable order Aggregate Root example, BenchmarkDotNet scenario, and updates pattern/benchmark catalogs + docs/README tables.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/PatternKit.Tests/Application/Aggregates/AggregateRootTests.cs | New TinyBDD coverage for aggregate root versioning/uncommitted events + command handler behavior. |
| test/PatternKit.Generators.Tests/AggregateCommandHandlerGeneratorTests.cs | Verifies generated factory output and validates diagnostics PKAGG001–PKAGG005. |
| test/PatternKit.Generators.Tests/AbstractionsAttributeCoverageTests.cs | Adds coverage ensuring new aggregate attributes expose defaults and validate ctor args. |
| test/PatternKit.Examples.Tests/ProductionReadiness/PatternKitPatternCatalogTests.cs | Updates expected catalog pattern names/counts to include Aggregate Root. |
| test/PatternKit.Examples.Tests/ProductionReadiness/PatternKitBenchmarkCoverageTests.cs | Updates expected published route-result total to account for the new pattern. |
| test/PatternKit.Examples.Tests/AggregateRootDemo/OrderAggregateRootDemoTests.cs | Ensures fluent vs generated parity and verifies DI import paths. |
| src/PatternKit.Generators/AnalyzerReleases.Unshipped.md | Documents new generator diagnostics PKAGG001–PKAGG005. |
| src/PatternKit.Generators/Aggregates/AggregateCommandHandlerGenerator.cs | New incremental generator emitting an aggregate command handler factory. |
| src/PatternKit.Generators.Abstractions/Aggregates/AggregateAttributes.cs | Adds [GenerateAggregateCommandHandler], [AggregateDecision], [AggregateEventApplier]. |
| src/PatternKit.Examples/ProductionReadiness/PatternKitPatternCatalog.cs | Registers “Aggregate Root” in the production pattern catalog with links to assets/tests/docs. |
| src/PatternKit.Examples/ProductionReadiness/PatternKitExampleCatalog.cs | Registers “Order Aggregate Root Pattern” in the example catalog. |
| src/PatternKit.Examples/DependencyInjection/PatternKitExampleServiceCollectionExtensions.cs | Adds DI wiring to import the new example via AddPatternKitExamples(). |
| src/PatternKit.Examples/AggregateRootDemo/OrderAggregateRootDemo.cs | Adds fluent + generated demo and an IServiceCollection extension + service wrapper. |
| src/PatternKit.Core/Application/Aggregates/AggregateRoot.cs | Introduces the core runtime Aggregate Root + command handler/result APIs. |
| README.md | Updates pattern counts/table and adds benchmark matrix rows for Aggregate Root. |
| docs/patterns/toc.yml | Adds Aggregate Root to pattern TOC. |
| docs/patterns/application/aggregate-root.md | New pattern documentation page for Aggregate Root (fluent + generated + IoC). |
| docs/index.md | Updates pattern counts/table on docs landing page. |
| docs/guides/pattern-coverage.md | Adds Aggregate Root row to the pattern coverage guide. |
| docs/guides/benchmarks.md | Adds Aggregate Root rows to benchmark guidance table. |
| docs/guides/benchmark-results.md | Updates counts and adds Aggregate Root to published benchmark results + generator matrix. |
| docs/generators/toc.yml | Adds Aggregate Root generator to generators TOC. |
| docs/generators/aggregate-root.md | New generator documentation page (usage, shapes, diagnostics). |
| docs/examples/toc.yml | Adds “Order Aggregate Root Pattern” to examples TOC. |
| docs/examples/order-aggregate-root-pattern.md | New example doc describing import/run/production notes. |
| benchmarks/PatternKit.Benchmarks/Application/AggregateRootBenchmarks.cs | Adds dedicated BenchmarkDotNet scenario for fluent vs generated aggregate handler construction/execution. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| private readonly List<TEvent> _uncommittedEvents = []; | ||
|
|
||
| protected AggregateRoot(TId id) | ||
| { |
| protected void Raise(TEvent domainEvent, Action<TEvent> apply) | ||
| { | ||
| if (apply is null) | ||
| throw new ArgumentNullException(nameof(apply)); | ||
|
|
||
| apply(domainEvent); | ||
| _uncommittedEvents.Add(domainEvent); | ||
| Version++; | ||
| } | ||
|
|
||
| protected void Replay(TEvent domainEvent, Action<TEvent> apply) | ||
| { | ||
| if (apply is null) | ||
| throw new ArgumentNullException(nameof(apply)); | ||
|
|
||
| apply(domainEvent); | ||
| Version++; | ||
| } |
| Handler = handler; | ||
| Events = events; |
Test Results 12 files 12 suites 10m 15s ⏱️ Results for commit e81fead. ♻️ This comment has been updated with latest results. |
🔍 PR Validation ResultsVersion: `` ✅ Validation Steps
📊 ArtifactsDry-run artifacts have been uploaded and will be available for 7 days. This comment was automatically generated by the PR validation workflow. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #408 +/- ##
==========================================
+ Coverage 89.57% 95.67% +6.09%
==========================================
Files 535 539 +4
Lines 43172 43432 +260
Branches 6230 6263 +33
==========================================
+ Hits 38672 41552 +2880
+ Misses 2029 1880 -149
+ Partials 2471 0 -2471
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
d932ab2 to
e81fead
Compare
Code Coverage |
Adds the next domain-modeling slice for #403: Aggregate Root.
Includes:
Local validation: