Skip to content

feat(messaging): add correlation identifier pattern#382

Merged
JerrettDavis merged 1 commit into
mainfrom
feature/correlation-identifier-pattern
May 27, 2026
Merged

feat(messaging): add correlation identifier pattern#382
JerrettDavis merged 1 commit into
mainfrom
feature/correlation-identifier-pattern

Conversation

@JerrettDavis

Copy link
Copy Markdown
Owner

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.

Copilot AI review requested due to automatic review settings May 27, 2026 04:40
@github-actions

Copy link
Copy Markdown
Contributor

⚠️ Deprecation Warning: The deny-licenses option is deprecated for possible removal in the next major release. For more information, see issue 997.

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +64 to +68
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();
Comment on lines +28 to +36
_ = 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);
@github-actions

Copy link
Copy Markdown
Contributor

Test Results

    1 files      1 suites   2m 10s ⏱️
1 040 tests 1 040 ✅ 0 💤 0 ❌
1 045 runs  1 045 ✅ 0 💤 0 ❌

Results for commit 65b9f18.

@codecov

codecov Bot commented May 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.53731% with 15 lines in your changes missing coverage. Please review.
✅ Project coverage is 95.60%. Comparing base (8efe707) to head (65b9f18).

Files with missing lines Patch % Lines
...ore/Messaging/Correlation/CorrelationIdentifier.cs 84.90% 8 Missing ⚠️
...les/Messaging/OrderCorrelationIdentifierExample.cs 87.50% 5 Missing ⚠️
...rators/Messaging/CorrelationIdentifierGenerator.cs 97.22% 2 Missing ⚠️
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     
Flag Coverage Δ
unittests 95.60% <92.53%> (+6.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions

Copy link
Copy Markdown
Contributor

🔍 PR Validation Results

Version: ``

✅ Validation Steps

  • Build solution
  • Run tests
  • Build documentation
  • Dry-run NuGet packaging

📊 Artifacts

Dry-run artifacts have been uploaded and will be available for 7 days.


This comment was automatically generated by the PR validation workflow.

@github-actions

Copy link
Copy Markdown
Contributor

Code Coverage

Summary
  Generated on: 05/27/2026 - 04:46:02
  Coverage date: 05/27/2026 - 04:44:17 - 05/27/2026 - 04:45:50
  Parser: MultiReport (9x Cobertura)
  Assemblies: 4
  Classes: 1575
  Files: 634
  Line coverage: 94.5%
  Covered lines: 41203
  Uncovered lines: 2362
  Coverable lines: 43565
  Total lines: 95315
  Branch coverage: 75.4% (12108 of 16039)
  Covered branches: 12108
  Total branches: 16039
  Method coverage: 95.9% (8248 of 8596)
  Full method coverage: 88.1% (7575 of 8596)
  Covered methods: 8248
  Fully covered methods: 7575
  Total methods: 8596

PatternKit.Core                                                                                                     95.3%
  PatternKit.Application.ActivityTracking.ActivityGateState                                                          100%
  PatternKit.Application.ActivityTracking.ActivityLease                                                              100%
  PatternKit.Application.ActivityTracking.ActivityRecord                                                             100%
  PatternKit.Application.ActivityTracking.ActivityTracker                                                            100%
  PatternKit.Application.AntiCorruption.AntiCorruptionLayer<T1, T2>                                                 90.4%
  PatternKit.Application.AntiCorruption.AntiCorruptionResult<T>                                                      100%
  PatternKit.Application.AuditLog.AuditLogAppendResult<T>                                                           85.7%
  PatternKit.Application.AuditLog.InMemoryAuditLog<T1, T2>                                                          95.4%
  PatternKit.Application.DataMapping.DataMapper<T1, T2>                                                             94.6%
  PatternKit.Application.DataMapping.DataMapperError                                                                  90%
  PatternKit.Application.DataMapping.DataMapperResult<T>                                                            84.6%
  PatternKit.Application.DomainEvents.DomainEventDispatcher<T>                                                      95.4%
  PatternKit.Application.DomainEvents.DomainEventDispatchResult                                                      100%
  PatternKit.Application.EventSourcing.EventStoreAppendResult                                                        100%
  PatternKit.Application.EventSourcing.InMemoryEventStore<T1, T2>                                                   97.9%
  PatternKit.Application.EventSourcing.StoredEvent<T1, T2>                                                            80%
  PatternKit.Application.FeatureToggles.FeatureToggleDecision                                                       87.5%
  PatternKit.Application.FeatureToggles.FeatureToggleRule<T>                                                         100%
  PatternKit.Application.FeatureToggles.FeatureToggleSet<T>                                                         96.9%
  PatternKit.Application.IdentityMap.IdentityMap<T1, T2>                                                             100%
  PatternKit.Application.IdentityMap.IdentityMapResult<T>                                                           92.8%
  PatternKit.Application.MaterializedViews.MaterializedView<T1, T2>                                                 98.4%
  PatternKit.Application.Repository.InMemoryRepository<T1, T2>                                                      92.8%
  PatternKit.Application.Repository.RepositoryResult<T>                                                             93.3%
  PatternKit.Application.ServiceLayer.ServiceLayerOperation<T1, T2>                                                 96.7%
  PatternKit.Application.ServiceLayer.ServiceLayerResult<T>                                                         94.7%
  PatternKit.Application.ServiceLayer.ServiceLayerRule<T>                                                            100%
  PatternKit.Application.Specification.Specification<T>                                                              100%
  PatternKit.Application.Specification.SpecificationRegistry<T>                                                     93.3%
  PatternKit.Application.TableDataGateway.InMemoryTableDataGateway<T1, T2>                                            86%
  PatternKit.Application.TableDataGateway.TableGatewayResult<T>                                                     82.3%
  PatternKit.Application.TransactionScript.TransactionScript<T1, T2>                                                  97%
  PatternKit.Application.TransactionScript.TransactionScriptError                                                     90%
  PatternKit.Application.TransactionScript.TransactionScriptResult<T>                                                100%
  PatternKit.Application.UnitOfWork.UnitOfWork                                                                      90.9%
  PatternKit.Application.UnitOfWork.UnitOfWorkResult                                                                94.7%
  PatternKit.Application.UnitOfWork.UnitOfWorkRollbackResult                                                         100%
  PatternKit.Application.UnitOfWork.UnitOfWorkStep                                                                   100%

@JerrettDavis
JerrettDavis merged commit 234079c into main May 27, 2026
13 checks passed
@JerrettDavis
JerrettDavis deleted the feature/correlation-identifier-pattern branch May 27, 2026 04:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Correlation Identifier enterprise integration pattern

2 participants