Skip to content

Add GetRegistrationId extension to expose a registration's unique ID (#1327)#1490

Merged
tillig merged 2 commits into
developfrom
feature/issue-1327
Jun 16, 2026
Merged

Add GetRegistrationId extension to expose a registration's unique ID (#1327)#1490
tillig merged 2 commits into
developfrom
feature/issue-1327

Conversation

@tillig

@tillig tillig commented Jun 16, 2026

Copy link
Copy Markdown
Member

Summary

Fixes #1327. There was no way to obtain a stable, unique identity for a registration from the IRegistrationBuilder returned by RegisterType / Register / RegisterInstance. The identity already exists internally (SingleRegistrationStyle.Id, which flows to IComponentRegistration.Id), but it was not reachable from the builder, so callers could not (for example) use it as a key in ContainerBuilder.Properties to track per-registration state before the container is built.

Fix

Adds a single extension method:

public static Guid GetRegistrationId<TLimit, TActivatorData>(
    this IRegistrationBuilder<TLimit, TActivatorData, SingleRegistrationStyle> registration)

It returns registration.RegistrationStyle.Id — the same Guid that appears on IComponentRegistration.Id after the container is built.

The method is generically constrained to SingleRegistrationStyle, so it is only callable on single-component registrations. Multi-component registrations (open generics via RegisterGeneric, assembly scanning, adapters, decorators) use DynamicRegistrationStyle and have no single stable identity — calling GetRegistrationId on them is a compile-time error rather than a runtime throw.

No interface changes (avoids breaking external implementers of IRegistrationBuilder); purely additive API. Placed alongside the similarly-constrained PreserveExistingDefaults.

Tests

6 tests (all tagged #1327): the returned id matches IComponentRegistration.Id after build for RegisterType, Register(lambda), and RegisterInstance; the id is stable across repeated calls; distinct registrations get distinct ids; and the null-argument guard. No compile test for the dynamic-style case is possible (it's a compile error by design).

Verified: the Guid is assigned once at SingleRegistrationStyle construction and never reassigned, flowing unchanged into IComponentRegistration.Id via RegistrationBuilder.CreateRegistration. Full XML docs; zero warnings; Autofac.Test passes; format clean.

Versioning

Because this adds new public API (a backwards-compatible additive surface change), this PR bumps the version in default.proj from 9.1.1 to 9.2.0 per semver. The bug fixes already merged to develop since 9.1.1 (#1485, #1486, #1487, #1488, #1489) will ship together in the 9.2.0 release.

…ions (#1327)

Adds a GetRegistrationId<TLimit, TActivatorData> extension method on
IRegistrationBuilder<TLimit, TActivatorData, SingleRegistrationStyle>
that returns the stable Guid identity of a registration before the
container is built. The generic constraint to SingleRegistrationStyle
ensures the method is only callable on RegisterType/Register/RegisterInstance
builders — attempting to call it on open-generic, scanning, adapter, or
decorator registrations is a compile-time error.
@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.93%. Comparing base (0e724c2) to head (40fe97d).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #1490      +/-   ##
===========================================
- Coverage    78.00%   77.93%   -0.08%     
===========================================
  Files          217      217              
  Lines         5897     5900       +3     
  Branches      1265     1266       +1     
===========================================
- Hits          4600     4598       -2     
- Misses         759      764       +5     
  Partials       538      538              

☔ 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 changed the title Add GetRegistrationId extension to expose a registration's unique id (#1327) Add GetRegistrationId extension to expose a registration's unique ID (#1327) Jun 16, 2026
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.

Ability to uniquely identify a registration object (IRegistrationBuilder<T,U,V>)

1 participant