feat: add Sidecar pattern#323
Conversation
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
Test Results1 438 tests 1 438 ✅ 16s ⏱️ Results for commit 4edfdb3. |
There was a problem hiding this comment.
Pull request overview
Adds a new “Sidecar” cloud-architecture pattern to PatternKit, including a fluent runtime API, a Roslyn incremental source generator (with diagnostics), a production-readiness catalog entry, and a DI + ASP.NET Core minimal API example.
Changes:
- Introduces
Sidecar<TRequest,TResponse>runtime with before/after companion steps and a primary handler result model. - Adds
[GenerateSidecar]/[SidecarBefore]/[SidecarAfter]/[SidecarHandler]attributes plusSidecarGeneratorwith PKSC001–PKSC004 diagnostics. - Adds an “Order Telemetry Sidecar” example (DI registration + endpoint mapping) and documents/catalogs the new pattern, generator, and 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/Cloud/Sidecar/SidecarTests.cs | Adds runtime coverage for sidecar execution order, failure behavior, and validation. |
| test/PatternKit.Generators.Tests/SidecarGeneratorTests.cs | Validates generator output and PKSC diagnostics for invalid declarations. |
| test/PatternKit.Generators.Tests/AbstractionsAttributeCoverageTests.cs | Extends attribute coverage tests to include Sidecar generator attributes. |
| test/PatternKit.Examples.Tests/SidecarDemo/OrderTelemetrySidecarDemoTests.cs | Adds example-level tests for fluent + DI-imported generated sidecar usage and catalog checks. |
| test/PatternKit.Examples.Tests/ProductionReadiness/PatternKitPatternCatalogTests.cs | Updates expected pattern lists/counts to include Sidecar in CloudArchitecture. |
| src/PatternKit.Generators/Sidecar/SidecarGenerator.cs | Implements the Sidecar source generator and diagnostics PKSC001–PKSC004. |
| src/PatternKit.Generators/AnalyzerReleases.Unshipped.md | Registers new analyzer IDs/descriptions for Sidecar diagnostics. |
| src/PatternKit.Generators.Abstractions/Cloud/SidecarAttributes.cs | Adds public generator attributes for Sidecar declarations. |
| src/PatternKit.Examples/SidecarDemo/OrderTelemetrySidecarDemo.cs | Adds runnable Sidecar example with DI and minimal API endpoint integration. |
| src/PatternKit.Examples/ProductionReadiness/PatternKitPatternCatalog.cs | Catalogs Sidecar pattern + generator + example assets for production readiness tracking. |
| src/PatternKit.Examples/ProductionReadiness/PatternKitExampleCatalog.cs | Adds “Order Telemetry Sidecar” example descriptor to the example catalog. |
| src/PatternKit.Examples/DependencyInjection/PatternKitExampleServiceCollectionExtensions.cs | Adds DI import helper for the new sidecar example and wires it into AddPatternKitExamples(). |
| src/PatternKit.Core/Cloud/Sidecar/Sidecar.cs | Introduces the Sidecar runtime types (SidecarContext, SidecarResult, Sidecar + builder). |
| docs/patterns/toc.yml | Adds Sidecar to the patterns documentation TOC. |
| docs/patterns/cloud/sidecar.md | Adds Sidecar pattern documentation and basic usage snippet. |
| docs/guides/pattern-coverage.md | Updates pattern coverage matrix to include Sidecar + generator. |
| docs/generators/toc.yml | Adds Sidecar generator doc to generators TOC. |
| docs/generators/sidecar.md | Adds Sidecar generator usage and diagnostic reference documentation. |
| docs/generators/index.md | Adds Sidecar to generator index and quick reference snippet. |
| docs/examples/toc.yml | Adds Order Telemetry Sidecar example to the examples TOC. |
| docs/examples/order-telemetry-sidecar.md | Adds short documentation page for the sidecar example. |
| docs/examples/index.md | Lists the new example in the examples index page. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| public Builder Before(string name, Action<SidecarContext<TRequest>> step) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(name)) | ||
| throw new ArgumentException("Sidecar step name is required.", nameof(name)); | ||
| if (step is null) | ||
| throw new ArgumentNullException(nameof(step)); | ||
| if (_before.Any(item => string.Equals(item.Name, name, StringComparison.OrdinalIgnoreCase))) | ||
| throw new InvalidOperationException($"Sidecar before step '{name}' is already registered."); | ||
|
|
| public Builder After(string name, Action<SidecarContext<TRequest>, TResponse> step) | ||
| { | ||
| if (string.IsNullOrWhiteSpace(name)) | ||
| throw new ArgumentException("Sidecar step name is required.", nameof(name)); | ||
| if (step is null) | ||
| throw new ArgumentNullException(nameof(step)); | ||
| if (_after.Any(item => string.Equals(item.Name, name, StringComparison.OrdinalIgnoreCase))) | ||
| throw new InvalidOperationException($"Sidecar after step '{name}' is already registered."); | ||
|
|
| var before = NamedMembers(type, BeforeAttributeName); | ||
| var after = NamedMembers(type, AfterAttributeName); | ||
| var handlers = MembersWith(type, HandlerAttributeName); | ||
| if (before.Length + after.Length == 0 || handlers.Length != 1) | ||
| { | ||
| context.ReportDiagnostic(Diagnostic.Create(MissingMembers, node.Identifier.GetLocation(), type.Name)); | ||
| return; | ||
| } | ||
|
|
||
| var duplicate = before.Concat(after).GroupBy(static item => item.Name, StringComparer.OrdinalIgnoreCase).FirstOrDefault(static group => group.Count() > 1); | ||
| if (duplicate is not null) | ||
| { | ||
| context.ReportDiagnostic(Diagnostic.Create(DuplicateStep, node.Identifier.GetLocation(), duplicate.Key)); | ||
| return; | ||
| } |
Code Coverage |
🔍 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 #323 +/- ##
==========================================
+ Coverage 89.96% 95.82% +5.85%
==========================================
Files 456 460 +4
Lines 37785 38077 +292
Branches 5377 5424 +47
==========================================
+ Hits 33994 36488 +2494
+ Misses 1685 1589 -96
+ Partials 2106 0 -2106
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:
|
Summary
Closes #316
Validation
SidecarGeneratorTests|FullyQualifiedNameAbstractionsAttributeCoverageTests" /p:BuildProjectReferences=false /p:UseSharedCompilation=falseSidecarGeneratorTests|FullyQualifiedNameAbstractionsAttributeCoverageTests" /p:BuildProjectReferences=false /p:UseSharedCompilation=falseSidecarGeneratorTests|FullyQualifiedNameAbstractionsAttributeCoverageTests" /p:BuildProjectReferences=false /p:UseSharedCompilation=falseNote: local full examples build remains blocked by the known CS9057 analyzer/compiler mismatch; hosted CI is authoritative for the full examples/docs pass.