Add [RegisterServices] support#3
Conversation
There was a problem hiding this comment.
Pull request overview
Adds support for [RegisterServices]-annotated methods so consumers can plug custom registration logic into the generated Add{Assembly}Services(...) extension method, with an analyzer enforcing the required method signature and new tests/snapshots validating output.
Changes:
- Extend the incremental generator pipeline to discover
[RegisterServices]methods and emitII.RegisterServicesMethods.g.csthat invokes them. - Add
RegisterServicesMethodAnalyzer(INJ0001) to enforce valid[RegisterServices]method signatures. - Add generator/analyzer tests and verified snapshots for the new generated output.
Reviewed changes
Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Immediate.Injections.Tests/Utility.cs | Adds metadata reference for RegisterServicesAttribute so test compilations can bind the attribute. |
| tests/Immediate.Injections.Tests/GeneratorTests/RegisterServicesTests.cs | New generator tests validating RegisterServices method discovery and invocation in generated output. |
| tests/Immediate.Injections.Tests/GeneratorTests/GeneratorTestHelper.cs | Updates tracked incremental steps list to include RegisterServicesMethods. |
| tests/Immediate.Injections.Tests/AnalyzerTests/RegisterServicesMethodAnalyzerTests.cs | New analyzer tests validating INJ0001 triggers/doesn’t trigger correctly. |
| tests/Immediate.Injections.Tests/GeneratorTests/Snapshots/RegisterServicesTests.ValidRegisterServicesMethodWhenLangVersionIs12#II.ServiceCollectionExtensions.g.verified.cs | Snapshot for generated service collection extensions when language version is C# 12. |
| tests/Immediate.Injections.Tests/GeneratorTests/Snapshots/RegisterServicesTests.ValidRegisterServicesMethodWhenLangVersionIs12#II.RegisterServicesMethods.g.verified.cs | Snapshot for generated RegisterServices implementation (C# 12 scenario). |
| tests/Immediate.Injections.Tests/GeneratorTests/Snapshots/RegisterServicesTests.ValidRegisterServicesMethodIsCalled1#II.ServiceCollectionExtensions.g.verified.cs | Snapshot for generated extensions (default language version) calling RegisterServices. |
| tests/Immediate.Injections.Tests/GeneratorTests/Snapshots/RegisterServicesTests.ValidRegisterServicesMethodIsCalled1#II.RegisterServicesMethods.g.verified.cs | Snapshot for generated RegisterServices implementation calling a services-only method. |
| tests/Immediate.Injections.Tests/GeneratorTests/Snapshots/RegisterServicesTests.ValidRegisterServicesMethodIsCalled2#II.ServiceCollectionExtensions.g.verified.cs | Snapshot for generated extensions with params ReadOnlySpan<string> tags. |
| tests/Immediate.Injections.Tests/GeneratorTests/Snapshots/RegisterServicesTests.ValidRegisterServicesMethodIsCalled2#II.RegisterServicesMethods.g.verified.cs | Snapshot for generated RegisterServices implementation calling a (services, tags) method. |
| src/Immediate.Injections.Generators/ImmediateInjectionsGenerator.cs | Adds a new syntax provider pipeline for [RegisterServices] methods and wires rendering. |
| src/Immediate.Injections.Generators/ImmediateInjectionsGenerator.Transform.cs | Adds transformation to RegisterServicesMethod model including fully-qualified callable name and whether it takes tags. |
| src/Immediate.Injections.Generators/ImmediateInjectionsGenerator.Render.cs | Adds rendering path for II.RegisterServicesMethods.g.cs via a new Scriban template. |
| src/Immediate.Injections.Generators/ImmediateInjectionsGenerator.Models.cs | Adds RegisterServicesMethod model record for template rendering. |
| src/Immediate.Injections.Generators/Templates/RegisterServices.sbntxt | New template that emits RegisterServices(...) implementation invoking discovered methods. |
| src/Immediate.Injections.Generators/DisplayNameFormatters.cs | Adds a symbol display format used to generate callable method names. |
| src/Immediate.Injections.Analyzers/RegisterServicesMethodAnalyzer.cs | New analyzer rule INJ0001 enforcing [RegisterServices] method signature constraints. |
| src/Immediate.Injections.Analyzers/DiagnosticIds.cs | Adds INJ0001 diagnostic id constant. |
| src/Immediate.Injections.Analyzers/AnalyzerReleases.Unshipped.md | Documents the new analyzer rule. |
| src/Common/Utility.cs | Adds WhereNotNull for IncrementalValuesProvider<T?>. |
| src/Common/ITypeSymbolExtensions.cs | Adds extension members to validate method signatures and identify relevant symbols/namespaces. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment Thanks for integrating Codecov - We've got you covered ☂️ |
No description provided.