feat: add domain event pattern support#260
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Test Results 1 files 1 suites 2m 2s ⏱️ Results for commit 7d53bd5. |
🔍 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. |
Code Coverage |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #260 +/- ##
==========================================
+ Coverage 90.68% 96.10% +5.41%
==========================================
Files 336 340 +4
Lines 30619 30907 +288
Branches 4292 4335 +43
==========================================
+ Hits 27768 29703 +1935
+ Misses 1271 1204 -67
+ Partials 1580 0 -1580
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:
|
There was a problem hiding this comment.
Pull request overview
Adds first-class Domain Event pattern support to PatternKit, including a runtime dispatcher, a Roslyn incremental generator for dispatcher factories, production-shaped DI/example integration, and catalog/docs updates.
Changes:
- Introduces
IDomainEvent,IDomainEventDispatcher<TEventBase>,DomainEventDispatcher<TEventBase>, andDomainEventDispatchResultinPatternKit.Application.DomainEvents. - Adds
GenerateDomainEventDispatcherAttribute/DomainEventHandlerAttribute+DomainEventDispatcherGeneratorwith diagnostics (PKDE001-PKDE004) and generator tests. - Adds an Order Domain Event example (fluent + generated paths), DI integration, docs, and catalog/coverage updates.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| test/PatternKit.Tests/Application/DomainEvents/DomainEventDispatcherTests.cs | Adds runtime dispatcher TinyBDD coverage (handled/unhandled/failed/validation). |
| test/PatternKit.Generators.Tests/DomainEventDispatcherGeneratorTests.cs | Adds generator output + diagnostics coverage for domain event generator. |
| test/PatternKit.Generators.Tests/AbstractionsAttributeCoverageTests.cs | Extends attribute coverage tests to include new domain event attributes. |
| test/PatternKit.Examples.Tests/ProductionReadiness/PatternKitPatternCatalogTests.cs | Updates catalog expectations to include the new Domain Event pattern. |
| test/PatternKit.Examples.Tests/DomainEventDemo/OrderDomainEventDemoTests.cs | Adds example-level verification for fluent/generated paths + DI importability. |
| test/PatternKit.Examples.Tests/DependencyInjection/PatternKitExampleDependencyInjectionTests.cs | Ensures the Domain Event example is resolved and runnable via IoC. |
| src/PatternKit.Generators/DomainEvents/DomainEventDispatcherGenerator.cs | Implements the incremental generator and diagnostics for dispatcher factories. |
| src/PatternKit.Generators/AnalyzerReleases.Unshipped.md | Registers new generator diagnostics in analyzer release notes. |
| src/PatternKit.Generators.Abstractions/DomainEvents/DomainEventAttributes.cs | Adds generator-facing attributes for dispatcher generation + handler ordering. |
| src/PatternKit.Examples/ProductionReadiness/PatternKitPatternCatalog.cs | Adds Domain Event to the pattern catalog with references to code/docs/tests. |
| src/PatternKit.Examples/ProductionReadiness/PatternKitExampleCatalog.cs | Adds “Order Domain Event Pattern” descriptor to example catalog. |
| src/PatternKit.Examples/DomainEventDemo/OrderDomainEventDemo.cs | Adds the production-shaped example (fluent + generated) and DI extensions. |
| src/PatternKit.Examples/DependencyInjection/PatternKitExampleServiceCollectionExtensions.cs | Wires the domain event example into the examples DI registration surface. |
| src/PatternKit.Core/Application/DomainEvents/DomainEventDispatcher.cs | Adds the runtime domain event dispatcher and result/status types. |
| docs/patterns/toc.yml | Adds Domain Event to patterns TOC under Application Architecture. |
| docs/patterns/application/domain-event.md | Adds pattern documentation for runtime dispatcher usage and guidance. |
| docs/guides/pattern-coverage.md | Updates coverage matrix to include Domain Event pattern/generator. |
| docs/generators/toc.yml | Adds Domain Event to generator docs TOC. |
| docs/generators/index.md | Adds Domain Event entry to generator index table. |
| docs/generators/domain-event.md | Adds generator documentation (usage, equivalence, diagnostics). |
| docs/examples/toc.yml | Adds Order Domain Event Pattern to examples TOC. |
| docs/examples/order-domain-event-pattern.md | Adds example documentation for fluent + generated + DI usage. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public async ValueTask<DomainEventDispatchResult> DispatchAsync(TEventBase domainEvent, CancellationToken cancellationToken = default) | ||
| { | ||
| if (domainEvent is null) | ||
| throw new ArgumentNullException(nameof(domainEvent)); | ||
|
|
||
| cancellationToken.ThrowIfCancellationRequested(); | ||
| var eventType = domainEvent.GetType(); | ||
| if (!_handlers.TryGetValue(eventType, out var handlers) || handlers.Count == 0) | ||
| return DomainEventDispatchResult.Unhandled(eventType); | ||
|
|
| private static List<HandlerConfig> GetHandlers(INamedTypeSymbol type) | ||
| { | ||
| var handlers = new List<HandlerConfig>(); | ||
| foreach (var method in type.GetMembers().OfType<IMethodSymbol>()) | ||
| { | ||
| foreach (var attribute in method.GetAttributes().Where(static attr => attr.AttributeClass?.ToDisplayString() == HandlerAttributeName)) | ||
| { | ||
| if (attribute.ConstructorArguments[0].Value is INamedTypeSymbol eventType) | ||
| handlers.Add(new HandlerConfig(method, eventType, (int)(attribute.ConstructorArguments[1].Value ?? 0))); | ||
| } |
| [GenerateDomainEventDispatcher(typeof(OrderDomainEvent), FactoryName = "CreateDispatcher", DispatcherName = "order-domain-events")] | ||
| public static partial class GeneratedOrderDomainEvents | ||
| { | ||
| public static OrderEventProjection Projection { get; set; } = new(); | ||
|
|
Closes #255.\n\nAdds the Domain Event application architecture pattern with a fluent runtime dispatcher, source-generated dispatcher factories, TinyBDD runtime/generator/example coverage, production-shaped IServiceCollection integration, and docs/catalog entries.