Skip to content

Add ScanForTypesAttribute as dedicated attribute for custom type handling#53

Merged
Dreamescaper merged 6 commits intomainfrom
copilot/add-custom-handler-attribute
Mar 20, 2026
Merged

Add ScanForTypesAttribute as dedicated attribute for custom type handling#53
Dreamescaper merged 6 commits intomainfrom
copilot/add-custom-handler-attribute

Conversation

Copy link
Contributor

Copilot AI commented Mar 20, 2026

GenerateServiceRegistrationsAttribute with CustomHandler set was awkward — registration-specific properties (Lifetime, AsSelf, AsImplementedInterfaces, KeySelector) are meaningless in that context, and the attribute name itself is misleading since the handler may not register anything.

Changes

  • New ScanForTypesAttribute — contains all filtering properties (AssignableTo, TypeNameFilter, AttributeFilter, etc.) and Handler, but none of the registration-specific ones
  • CustomHandler on GenerateServiceRegistrationsAttribute marked [Obsolete("Use ScanForTypesAttribute instead.", error: false)] — still functional
  • New diagnostics:
    • DI0013ScanForTypesAttribute used without Handler set
    • DI0014ScanForTypesAttribute and GenerateServiceRegistrationsAttribute used on the same method
  • Second incremental generator provider wired up for the new attribute, sharing the existing FindServicesToRegister / source generation pipeline
  • Version bumped to 3.0

Migration

// Before (deprecated)
[GenerateServiceRegistrations(AssignableTo = typeof(IEndpoint), CustomHandler = nameof(IEndpoint.MapEndpoint))]
public static partial IEndpointRouteBuilder MapEndpoints(this IEndpointRouteBuilder endpoints);

// After
[ScanForTypes(AssignableTo = typeof(IEndpoint), Handler = nameof(IEndpoint.MapEndpoint))]
public static partial IEndpointRouteBuilder MapEndpoints(this IEndpointRouteBuilder endpoints);
Original prompt

This section details on the original issue you should resolve

<issue_title>Create separate attribute for custom handling</issue_title>
<issue_description>Existing GenerateServiceRegistrations attribute becomes a bit messy. When CustomHandler is specified, properties like AsSelf, Lifetime, etc become incompatible.
Also, naming GenerateServiceRegistrations becomes incorrect, as CustomHandler does not nessesary does anything regarding registrations.

We should add a separate attribute, which only applies to CustomHandler. It should contain all filtering properties, but nothing related to service registration.
Existing CustomHandler on GenerateServiceRegistrations attribute should be marked as Obsolete (but functional for now).</issue_description>

Comments on the Issue (you are @copilot in this section)


📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

…e on GenerateServiceRegistrationsAttribute

Co-authored-by: Dreamescaper <17177729+Dreamescaper@users.noreply.github.com>
Copilot AI changed the title [WIP] Add separate attribute for custom handling Add GenerateServiceHandlerAttribute as dedicated attribute for custom type handling Mar 20, 2026
Copilot AI requested a review from Dreamescaper March 20, 2026 12:44
@Dreamescaper
Copy link
Owner

@copilot
Bump major version in version.json

Co-authored-by: Dreamescaper <17177729+Dreamescaper@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 20, 2026

@copilot
Bump major version in version.json

Done in f138be0 — bumped version from 2.4 to 3.0.

@Dreamescaper Dreamescaper marked this pull request as ready for review March 20, 2026 12:55
@Dreamescaper
Copy link
Owner

@copilot
I suggest to rename GenerateServiceHandler to ScanForTypes (we'll add other functionality later, like returning found types as a collection).
Also, CustomHandler -> Handler (no point specifying that it is custom now when it is separate from registration attribute).

Let me know if you have other naming suggestions.

…omHandler to Handler

Co-authored-by: Dreamescaper <17177729+Dreamescaper@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 20, 2026

@copilot
I suggest to rename GenerateServiceHandler to ScanForTypes (we'll add other functionality later, like returning found types as a collection).
Also, CustomHandler -> Handl...

Done in dfd4989:

  • GenerateServiceHandlerAttributeScanForTypesAttribute
  • CustomHandler property on the new attribute → Handler

The [Obsolete] on GenerateServiceRegistrationsAttribute.CustomHandler now points to ScanForTypesAttribute. The AttributeModel reads "Handler" first, then falls back to "CustomHandler" so both the new and legacy attributes work correctly.

Copilot AI changed the title Add GenerateServiceHandlerAttribute as dedicated attribute for custom type handling Add ScanForTypesAttribute as dedicated attribute for custom type handling Mar 20, 2026
@Dreamescaper
Copy link
Owner

@copilot
Merge lastest main and fix the build.

Copilot AI and others added 2 commits March 20, 2026 13:19
… [Conditional]

Co-authored-by: Dreamescaper <17177729+Dreamescaper@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Mar 20, 2026

@copilot
Merge lastest main and fix the build.

Done in 2291b64. Merged latest main (the "Use Embedded API" commit) and fixed ScanForTypesAttribute to use [Embedded] instead of [Conditional("CODE_ANALYSIS")], plus updated the three new ScanForTypes test assertions from GeneratedTrees[1] to GeneratedTrees[2] to account for the extra EmbeddedAttribute generated tree. All 82 tests pass and the Playground project builds cleanly.

Copilot AI requested a review from Dreamescaper March 20, 2026 13:21
@Dreamescaper Dreamescaper merged commit d14cace into main Mar 20, 2026
1 check passed
@Dreamescaper Dreamescaper deleted the copilot/add-custom-handler-attribute branch March 20, 2026 13:27
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.

Create separate attribute for custom handling

2 participants