Skip to content

Add WithAttributedMetadata for individual registrations - #22

Merged
tillig merged 1 commit into
developfrom
feature/attributed-metadata-single-registration
Aug 14, 2026
Merged

Add WithAttributedMetadata for individual registrations#22
tillig merged 1 commit into
developfrom
feature/attributed-metadata-single-registration

Conversation

@tillig

@tillig tillig commented Aug 14, 2026

Copy link
Copy Markdown
Member

Closes #11.

Rebased onto develop now that #21 is merged; this PR is a single commit.

Problem

Attributed metadata could only be opted into via assembly scanning. Individual registrations had to fall back to AttributedMetadataModule, so the two registration styles behaved differently for no good reason.

Change

One new overload, so RegisterType and RegisterAssemblyTypes opt in the same way:

builder.RegisterType<CenturyArtwork>().As<IArtwork>().WithAttributedMetadata();

Design note

The natural shape - an arity-3 overload constrained to ReflectionActivatorData - does not compile. ScanningActivatorData derives from ReflectionActivatorData, and generic constraints are not part of a method signature, so it is a duplicate of the existing scanning overload and fails with CS0111. I verified this rather than assuming it.

Closing over ConcreteReflectionActivatorData/SingleRegistrationStyle instead sidesteps that, and is exactly what RegisterType<T>() and RegisterType(Type) return. There is a test asserting the scanning overload still binds unambiguously.

Scope

Covers reflection-based registrations, where the implementation type is known at registration time. Delegate registrations (Register(c => ...)) have no ImplementationType and still need the module; that limitation is documented on the method.

The open question in #11

Make sure that if both the AttributedMetadataModule and the WithAttributedMetadata extension are used that we don't have conflict issues.

No conflict. AttributedMetadataModule skips metadata keys that are already present, so metadata is applied once rather than throwing on a duplicate key. Covered by a test.

Verification

dotnet msbuild ./default.proj clean: 22/22 tests pass on net10.0 and net8.0 (17 plus 5 new), zero warnings, packages build. dotnet format --verify-no-changes is clean.

@codecov

codecov Bot commented Aug 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.52%. Comparing base (abb7343) to head (38d5150).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop      #22      +/-   ##
===========================================
+ Coverage    54.54%   56.52%   +1.97%     
===========================================
  Files            4        4              
  Lines           66       69       +3     
  Branches        23       24       +1     
===========================================
+ Hits            36       39       +3     
  Misses          14       14              
  Partials        16       16              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@tillig
tillig force-pushed the feature/attributed-metadata-single-registration branch from 51a438e to 6971c58 Compare August 14, 2026 20:16
Closes #11.

Attributed metadata could only be opted into via assembly scanning; individual
registrations had to rely on AttributedMetadataModule, which made the two
registration styles inconsistent.

The overload is closed over ConcreteReflectionActivatorData/
SingleRegistrationStyle rather than constrained to ReflectionActivatorData,
because ScanningActivatorData derives from ReflectionActivatorData and
constraints are not part of the method signature, so the latter collides with
the existing scanning overload (CS0111).
@tillig
tillig force-pushed the feature/attributed-metadata-single-registration branch from 6971c58 to 38d5150 Compare August 14, 2026 20:20
@tillig
tillig merged commit bda2dcd into develop Aug 14, 2026
12 checks passed
@tillig
tillig deleted the feature/attributed-metadata-single-registration branch August 14, 2026 20:43
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.

WithAttributedMetadata for individual registrations

1 participant