Repository navigation
Extract service-type inference into ServiceTypeInference - #125
Merged
ipjohnson merged 1 commit intoOct 27, 2026
Merged
Conversation
The helper takes the resolved base-list symbols of the attributed declaration, so an analyzer can compute the same service type the generator registers. It reads only that declaration's base list, as before, so a partial class still ignores interfaces on other parts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Agent-Driver-Session: 7fe21b70-797d-48ed-bb50-28190be670fb
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.
What changed
The service-type inference moves out of
ServiceModelUtilityinto a new public static class,ServiceTypeInference, insrc/DependencyModules.SourceGenerator.Impl/Utilities/ServiceTypeInference.cs.ServiceModelUtility.GetServiceTypeFromClassnow resolves the base list withServiceTypeInference.BaseListSymbolsand callsServiceTypeInference.GetServiceType. TheAspath callsServiceTypeInference.ReplaceGenericParametersForRegistration._capabilityInterfaces,GetBaseTypeRegistration,GetBaseInterfaceandSkipInterfacemoved unchanged as private members.The helper takes the base-list symbols of the attributed declaration, not one type symbol. The generator reads only that declaration's base list, so an interface on another part of a partial class is not used.
INamedTypeSymbol.Interfacesmerges all parts and would change behaviour.The class doc comment records that a factory-method registration infers nothing. Its service type is the method's declared return type.
Closes #123
Why
The DM0026 analyzer and its code fix (#122) must compute the same service type as the generator. A shared helper that takes symbols lets them call the same code.
How it was tested
dotnet test tests/DependencyModules.Tests -c Release: 1086 passed on net8.0 and net10.0.PublicApiTests.SourceGeneratorApi.verified.txtadds only the new class.dotnet csharpier check src testspasses.ServiceRegistrationTests.FactoryMethod_RegistersItsDeclaredReturnTypechecks the factory-method behaviour through the generator.ServiceTypeInferenceTestscalls the helper on symbols: first role interface, interface from a base class, open generic, and an interface on another partial part that is ignored.Review guide
Start with
ServiceTypeInference.cs, then the small change at the end ofServiceModelUtility.cs. CompareGetBaseTypeRegistrationwith the removed code to confirm that the loop is the same. The only difference is that symbol resolution moved intoBaseListSymbols, which is lazy so that binding still stops at the first interface taken. Check by hand that the factory-method paragraph of the class doc comment matches what you expect DM0026 to report. No questions were asked or answered for this change.🤖 Generated with Claude Code
Agent Driver: sessions 7fe21b70 and a7573f27, Task 467d4213 (Require explicit As on service attributes), item extract-service-type-inference-into-a-sh. Open on your network