feat(messaging): add correlation identifier pattern#382
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
This PR introduces the Correlation Identifier enterprise integration pattern to PatternKit, including a fluent core API, a Roslyn source generator + attribute, a production-shaped DI example, TinyBDD test coverage, documentation, and BenchmarkDotNet coverage updates.
Changes:
- Added
CorrelationIdentifier<TPayload>to ensure/copy correlation IDs across message flows (including request/reply). - Added
[GenerateCorrelationIdentifier]and an incremental generator that emits a typed factory returning a configured builder. - Added production-readiness catalog entries, docs, example runner + DI registration, tests, and benchmark rows/coverage counts.
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/Messaging/Correlation/CorrelationIdentifierTests.cs | TinyBDD coverage for fluent correlation behavior and builder validation. |
| test/PatternKit.Generators.Tests/CorrelationIdentifierGeneratorTests.cs | Generator test coverage for factory emission + diagnostics. |
| test/PatternKit.Generators.Tests/AbstractionsAttributeCoverageTests.cs | Adds attribute coverage assertions for the new generator attribute. |
| test/PatternKit.Examples.Tests/ProductionReadiness/PatternKitPatternCatalogTests.cs | Updates expected catalog entries/counts to include Correlation Identifier. |
| test/PatternKit.Examples.Tests/ProductionReadiness/PatternKitBenchmarkCoverageTests.cs | Updates expected published benchmark route-result totals for the new pattern. |
| test/PatternKit.Examples.Tests/Messaging/OrderCorrelationIdentifierExampleTests.cs | Verifies fluent, generated, and DI-based example usage. |
| src/PatternKit.Generators/Messaging/CorrelationIdentifierGenerator.cs | New incremental generator for correlation identifier factory emission. |
| src/PatternKit.Generators/AnalyzerReleases.Unshipped.md | Registers new diagnostic IDs (PKCI001/PKCI002). |
| src/PatternKit.Generators.Abstractions/Messaging/CorrelationIdentifierAttributes.cs | Adds [GenerateCorrelationIdentifier] attribute definition. |
| src/PatternKit.Examples/ProductionReadiness/PatternKitPatternCatalog.cs | Adds the pattern’s docs/code/tests/generator/example pointers to the catalog. |
| src/PatternKit.Examples/ProductionReadiness/PatternKitExampleCatalog.cs | Adds the “Order Correlation Identifier” example descriptor. |
| src/PatternKit.Examples/Messaging/OrderCorrelationIdentifierExample.cs | New production-shaped example demonstrating fluent, generated, and DI usage. |
| src/PatternKit.Examples/DependencyInjection/PatternKitExampleServiceCollectionExtensions.cs | Wires the example into the repo-wide example DI registration surface. |
| src/PatternKit.Core/Messaging/Correlation/CorrelationIdentifier.cs | New core pattern implementation + fluent builder API. |
| README.md | Updates pattern totals and adds benchmark rows for Correlation Identifier. |
| docs/patterns/toc.yml | Adds Correlation Identifier to the patterns TOC. |
| docs/patterns/messaging/correlation-identifier.md | Adds pattern documentation and usage snippets. |
| docs/guides/pattern-coverage.md | Adds pattern-to-generator mapping entry. |
| docs/guides/benchmarks.md | Adds benchmark rows for Correlation Identifier. |
| docs/guides/benchmark-results.md | Adds benchmark rows and updates coverage summary totals/matrix entries. |
| docs/generators/toc.yml | Adds generator doc entry to generators TOC. |
| docs/generators/index.md | Adds generator index row for Correlation Identifier. |
| docs/generators/correlation-identifier.md | Adds generator documentation and usage snippet. |
| docs/examples/toc.yml | Adds the example doc entry to examples TOC. |
| docs/examples/order-correlation-identifier.md | Adds example documentation and DI import snippet. |
| benchmarks/PatternKit.Benchmarks/Messaging/CorrelationIdentifierBenchmarks.cs | Adds construction/execution benchmarks for fluent vs generated paths. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var value = string.IsNullOrWhiteSpace(selected) ? _generator() : selected!; | ||
| if (string.IsNullOrWhiteSpace(value)) | ||
| throw new InvalidOperationException("Correlation identifier selector returned an empty value."); | ||
|
|
||
| return message.WithHeader(_headerName, value); |
|
|
||
| var correlationId = request.Headers.GetString(_headerName) ?? request.Headers.MessageId; | ||
| if (string.IsNullOrWhiteSpace(correlationId)) | ||
| correlationId = _generator(); |
| _ = RoslynTestHelpers.Run(comp, new CorrelationIdentifierGenerator(), out var run, out _); | ||
| return run.Results.Single().GeneratedSources.Single().SourceText.ToString(); | ||
| }) | ||
| .Then("the generated factory returns a configured builder", text => | ||
| { | ||
| ScenarioExpect.Contains("CorrelationIdentifier<global::MyApp.Order>.Builder Build()", text); | ||
| ScenarioExpect.Contains("CorrelationIdentifier<global::MyApp.Order>.Create()", text); | ||
| ScenarioExpect.Contains(".Header(@\"X-Correlation\")", text); | ||
| ScenarioExpect.Contains(".PreserveExisting(false)", text); |
Test Results 1 files 1 suites 2m 10s ⏱️ Results for commit 65b9f18. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #382 +/- ##
==========================================
+ Coverage 89.58% 95.60% +6.01%
==========================================
Files 514 518 +4
Lines 41833 42034 +201
Branches 6037 6070 +33
==========================================
+ Hits 37477 40187 +2710
+ Misses 1981 1847 -134
+ Partials 2375 0 -2375
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 #381
Adds the Correlation Identifier enterprise integration pattern with fluent and source-generated configuration, production-shaped IServiceCollection examples, TinyBDD coverage, documentation, and BenchmarkDotNet timing/allocation rows.
Validation: build, core tests, generator tests, example tests, focused CorrelationIdentifier benchmarks.