Skip to content

Extract service-type inference into ServiceTypeInference - #125

Merged
ipjohnson merged 1 commit into
mainfrom
agent/123-extract-service-type-inference-into-a-sh
Oct 27, 2026
Merged

ipjohnson merged 1 commit into
mainfrom
agent/123-extract-service-type-inference-into-a-sh

Conversation

@ipjohnson

@ipjohnson ipjohnson commented Oct 27, 2026 •

Copy link
Copy Markdown
Owner

What changed

The service-type inference moves out of ServiceModelUtility into a new public static class, ServiceTypeInference, in src/DependencyModules.SourceGenerator.Impl/Utilities/ServiceTypeInference.cs. ServiceModelUtility.GetServiceTypeFromClass now resolves the base list with ServiceTypeInference.BaseListSymbols and calls ServiceTypeInference.GetServiceType. The As path calls ServiceTypeInference.ReplaceGenericParametersForRegistration. _capabilityInterfaces, GetBaseTypeRegistration, GetBaseInterface and SkipInterface moved 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.Interfaces merges 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.
  • No generator snapshot changed. PublicApiTests.SourceGeneratorApi.verified.txt adds only the new class.
  • dotnet csharpier check src tests passes.
  • New ServiceRegistrationTests.FactoryMethod_RegistersItsDeclaredReturnType checks the factory-method behaviour through the generator.
  • New ServiceTypeInferenceTests calls 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 of ServiceModelUtility.cs. Compare GetBaseTypeRegistration with the removed code to confirm that the loop is the same. The only difference is that symbol resolution moved into BaseListSymbols, 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

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
@ipjohnson
ipjohnson merged commit 10af95c into main Oct 27, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extract service-type inference into a shared helper

1 participant