Add GetRegistrationId extension to expose a registration's unique ID (#1327)#1490
Merged
Conversation
…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 Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
This was referenced Jun 17, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1327. There was no way to obtain a stable, unique identity for a registration from the
IRegistrationBuilderreturned byRegisterType/Register/RegisterInstance. The identity already exists internally (SingleRegistrationStyle.Id, which flows toIComponentRegistration.Id), but it was not reachable from the builder, so callers could not (for example) use it as a key inContainerBuilder.Propertiesto track per-registration state before the container is built.Fix
Adds a single extension method:
It returns
registration.RegistrationStyle.Id— the sameGuidthat appears onIComponentRegistration.Idafter 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 viaRegisterGeneric, assembly scanning, adapters, decorators) useDynamicRegistrationStyleand have no single stable identity — callingGetRegistrationIdon 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-constrainedPreserveExistingDefaults.Tests
6 tests (all tagged
#1327): the returned id matchesIComponentRegistration.Idafter build forRegisterType,Register(lambda), andRegisterInstance; 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
Guidis assigned once atSingleRegistrationStyleconstruction and never reassigned, flowing unchanged intoIComponentRegistration.IdviaRegistrationBuilder.CreateRegistration. Full XML docs; zero warnings;Autofac.Testpasses; format clean.Versioning
Because this adds new public API (a backwards-compatible additive surface change), this PR bumps the version in
default.projfrom9.1.1to9.2.0per semver. The bug fixes already merged todevelopsince 9.1.1 (#1485, #1486, #1487, #1488, #1489) will ship together in the 9.2.0 release.