Skip to content

Support external ScanForTypes handlers via nameof(Type.Method)#61

Draft
Copilot wants to merge 4 commits intomainfrom
copilot/support-handler-method-other-assembly
Draft

Support external ScanForTypes handlers via nameof(Type.Method)#61
Copilot wants to merge 4 commits intomainfrom
copilot/support-handler-method-other-assembly

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 24, 2026

ScanForTypes accepted Handler as a method name, but only resolved handlers on the containing type or on matched scanned types. This updates Handler = nameof(SomeType.Method) to also resolve static generic handlers declared on another referenced type/assembly.

  • Handler resolution

    • Capture the declaring type from nameof(Type.Method) during attribute parsing
    • Resolve external static generic handlers during validation and source generation
    • Emit fully qualified invocations for external handlers
  • Behavior preserved

    • Local and inherited handler methods continue to resolve as before
    • Static handler methods on matched scanned types still use the matched type path
    • Existing HandlerTemplate behavior is unchanged
  • Docs

    • Clarify that Handler supports nameof(OtherType.Method)
  • Coverage

    • Add focused tests for:
      • external handler methods returning collection items
      • external handlers with matched generic arguments
      • alias-qualified nameof expressions

Example:

[ScanForTypes(
    AssignableTo = typeof(ICommandHandler<>),
    Handler = nameof(Shared.Extensions.DecorateCommandHandler)
)]
private static partial IServiceCollection AddTransactionalProcessing(
    this IServiceCollection services
);

Generates calls like:

global::Shared.Extensions.DecorateCommandHandler<
    global::MyModule.CreateOrderHandler,
    global::MyModule.CreateOrder
>(services);

Copilot AI and others added 3 commits April 24, 2026 16:28
Copilot AI changed the title [WIP] Add support for handler method from other assembly for ScanForTypes Support external ScanForTypes handlers via nameof(Type.Method) Apr 24, 2026
Copilot AI requested a review from Dreamescaper April 24, 2026 16:34
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.

Support Handler method from other assembly for ScanForTypes attribute

2 participants