Add decorator registration support with compile-time validation#303
Draft
Add decorator registration support with compile-time validation#303
Conversation
Adds RegisterDecoratorAttribute (non-generic and generic variants) for wrapping existing service registrations with decorator classes. The generator emits a self-contained runtime helper (Injectio.Decoration.g.cs) so no new package dependencies are introduced. - Supports chaining via Order (lower = innermost) - Supports keyed decoration, AnyKey, open-generic (closed instances), factory-built decorators, and tag filtering - Adds diagnostics INJ0010-INJ0016 for decorator validation - Runtime helpers use ActivatorUtilities for DI-friendly construction https://claude.ai/code/session_01DFMTsCCwsWoYM7vWumE6mw
Coverage Report for CI Build 24800355082Coverage increased (+0.8%) to 87.278%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds comprehensive decorator registration support to Injectio, allowing services to be wrapped with decorators without runtime dependencies. The implementation includes a new
RegisterDecoratorattribute, compile-time diagnostics for decorator validation, and code generation for decorator application.Key Changes
New
RegisterDecoratorAttribute: AddedRegisterDecoratorAttributeto mark classes as decorators for existing services, supporting:AnyKey)OrderpropertyCompile-Time Validation: Extended
ServiceRegistrationAnalyzerwith decorator-specific diagnostics:Code Generation:
ServiceRegistrationWriterto generate decorator registration callsGenerateDecorationHelper()to emit decoration extension methods (Decorate<T>,DecorateKeyed<T>,DecorateOpenGeneric)ActivatorUtilitiesand custom factory methodsAnalyzer Enhancement: Implemented
AnalyzeCompilationto perform cross-symbol analysis:Test Coverage: Added comprehensive test suite (
ServiceRegistrationDecoratorTests) with:Notable Implementation Details
https://claude.ai/code/session_01DFMTsCCwsWoYM7vWumE6mw