Add Decorate<TDecorated, TDecorator> support#325
Merged
Conversation
Member
Author
🧪 Details on Ubuntu 24.04.4 LTSfrom retest v1.1.0 on .NET 10.0.9 with 💜 by @devlooped |
Co-authored-by: Daniel Cazzulino <daniel@cazzulino.com>
Co-authored-by: Daniel Cazzulino <daniel@cazzulino.com>
Co-authored-by: Daniel Cazzulino <daniel@cazzulino.com>
Co-authored-by: Daniel Cazzulino <daniel@cazzulino.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Showcase the Decorate feature in the sample app with a stopwatch timer decorator on the echo command handler, and document usage in the readme including keyed decoration.
…eyed paths
- [Service] is no longer required on TDecorator for Decorate<TDecorated, TDecorator>.
Lifetime compatibility validation is now only performed when the decorator
actually declares [Service] (or keyed variant) attributes.
- Reduced duplication between keyed and non-keyed code:
- Runtime helpers: unified DecorateDescriptors (now handles key=null for
non-keyed) and GetDecoratedCore (single implementation of the
Instance/Factory/ImplementationType materialization logic).
- Generator: extracted BuildDecoratorArgs helper to eliminate duplicated
constructor argument emission for CreateDecoratorN / CreateKeyedDecoratorN.
- Cleanups:
- Removed DecoratorMustBeService (DDI006) diagnostic and the associated
generator test (ErrorIfDecoratorIsNotService).
- Removed legacy DecorateKeyedDescriptors forwarding method; generator now
emits calls to the unified DecorateDescriptors overload.
- Updated readme documentation to reflect that [Service] on the decorator
is optional.
- Added NoErrorIfDecoratorHasNoServiceAttribute (generator) and
DecorateWorksWithDecoratorThatHasNoServiceAttribute (end-to-end) tests.
- Added the README 'Decorating Services' example as
DecorateServiceReadmeExample in GenerationTests.
- Existing behavior preserved when [Service] is present on the decorator
(lifetime checks, suppression via IsDecoratorServiceAlias, etc.).
Add regression test verifying that constructor-injected IEnumerable<TDecorated> receives properly decorated instances for each underlying registration after Decorate<TDecorated, TDecorator>() is applied.
7837506 to
ec4ee62
Compare
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.
Fixes #215
Summary
Decorate<TDecorated, TDecorator>()as a source-generator marker extension.Decorate<TDecorated, TDecorator>(object? key)for decorating keyed service registrations by key.[Service], incompatible lifetimes, and constructors without exactly one decorated-service parameter.Validation
dotnet test src/CodeAnalysis.Tests/CodeAnalysis.Tests.csproj -m:1dotnet test src/DependencyInjection.Tests/DependencyInjection.Tests.csproj -m:1Slack Thread