feat: add event sourcing pattern support#262
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Test Results 1 files 1 suites 2m 36s ⏱️ Results for commit 0e1577d. |
There was a problem hiding this comment.
Pull request overview
Adds a first-class Event Sourcing “pattern slice” to PatternKit, including a minimal in-memory event store runtime, a Roslyn generator for store factories, and corresponding docs/examples/tests to integrate it into the pattern catalog.
Changes:
- Introduces
IEventStore<TEvent,TStreamId>+InMemoryEventStore<TEvent,TStreamId>with optimistic concurrency via expected stream version. - Adds
[GenerateEventStore]+EventStoreGeneratorto emit typed in-memory event store factories, plus analyzer release notes and generator tests. - Adds an order-focused event sourcing demo, DI wiring, catalog entries, and documentation pages (pattern, generator, example).
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/EventSourcing/EventStoreTests.cs | Adds runtime coverage for append/read, conflict behavior, and argument validation. |
| test/PatternKit.Generators.Tests/EventStoreGeneratorTests.cs | Verifies generator output and diagnostics for invalid declarations. |
| test/PatternKit.Generators.Tests/AbstractionsAttributeCoverageTests.cs | Extends attribute coverage tests for the new generator attribute. |
| test/PatternKit.Examples.Tests/ProductionReadiness/PatternKitPatternCatalogTests.cs | Updates catalog expectations to include Event Sourcing. |
| test/PatternKit.Examples.Tests/EventSourcingDemo/OrderEventSourcingDemoTests.cs | Adds example-level tests for fluent vs generated paths and DI import. |
| test/PatternKit.Examples.Tests/DependencyInjection/PatternKitExampleDependencyInjectionTests.cs | Ensures the new example is registered and runnable through DI. |
| src/PatternKit.Generators/EventSourcing/EventStoreGenerator.cs | Implements the incremental generator for event store factories. |
| src/PatternKit.Generators/AnalyzerReleases.Unshipped.md | Documents the new generator diagnostic ID. |
| src/PatternKit.Generators.Abstractions/EventSourcing/EventSourcingAttributes.cs | Adds [GenerateEventStore] attribute definition in the abstractions package. |
| src/PatternKit.Examples/ProductionReadiness/PatternKitPatternCatalog.cs | Registers the Event Sourcing pattern entry and its artifacts in the catalog. |
| src/PatternKit.Examples/ProductionReadiness/PatternKitExampleCatalog.cs | Adds the “Order Event Sourcing Pattern” example descriptor. |
| src/PatternKit.Examples/EventSourcingDemo/OrderEventSourcingDemo.cs | Adds the order event sourcing demo, projection, workflow, DI extension, and generated store host. |
| src/PatternKit.Examples/DependencyInjection/PatternKitExampleServiceCollectionExtensions.cs | Wires the event sourcing example into the main examples DI registration. |
| src/PatternKit.Core/Application/EventSourcing/EventStore.cs | Introduces the core event store abstractions and in-memory implementation. |
| docs/patterns/toc.yml | Adds Event Sourcing to the patterns TOC. |
| docs/patterns/application/event-sourcing.md | Adds the Event Sourcing pattern documentation page. |
| docs/guides/pattern-coverage.md | Extends pattern coverage matrix with Event Sourcing. |
| docs/generators/toc.yml | Adds Event Sourcing to the generators TOC. |
| docs/generators/index.md | Adds Event Sourcing row to the generators index table. |
| docs/generators/event-sourcing.md | Adds generator documentation for [GenerateEventStore]. |
| docs/examples/toc.yml | Adds the order event sourcing example to the examples TOC. |
| docs/examples/order-event-sourcing-pattern.md | Adds the order event sourcing example documentation page. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if (appendedCount < 0) | ||
| throw new ArgumentOutOfRangeException(nameof(appendedCount)); | ||
|
|
||
| return new(EventStoreAppendStatus.Committed, version, version, appendedCount); |
| cancellationToken.ThrowIfCancellationRequested(); | ||
| lock (_gate) | ||
| { | ||
| var currentVersion = _streams.TryGetValue(streamId, out var stream) ? stream.Count : 0; | ||
| if (currentVersion != expectedVersion) | ||
| return new(EventStoreAppendResult.Conflict(currentVersion, expectedVersion)); | ||
|
|
| var storeName = GetNamedString(attribute, "StoreName"); | ||
| if (string.IsNullOrWhiteSpace(storeName)) | ||
| storeName = type.Name; | ||
|
|
||
| context.AddSource($"{type.Name}.EventStore.g.cs", SourceText.From( | ||
| GenerateSource(type, eventType, streamIdType, GetNamedString(attribute, "FactoryName") ?? "Create", storeName!), | ||
| Encoding.UTF8)); |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #262 +/- ##
==========================================
+ Coverage 90.58% 96.05% +5.47%
==========================================
Files 344 348 +4
Lines 31128 31365 +237
Branches 4371 4407 +36
==========================================
+ Hits 28196 30129 +1933
+ Misses 1316 1236 -80
+ Partials 1616 0 -1616
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:
|
🔍 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 |
Closes #256.\n\nAdds Event Sourcing as an application architecture pattern with:\n- fluent in-memory event store runtime with optimistic concurrency\n- source-generated event store factory path\n- TinyBDD runtime, generator, example, catalog, and DI coverage\n- production-shaped order event sourcing demo and docs