Prefer a complete generic argument mapping for multi-interface open generics (#1464) - #1489
Merged
Conversation
…h service pattern (#1464) When an open-generic implementation type implements multiple interfaces that match the service's name/namespace pattern (e.g. IHandler<IRequest> and IHandler<IRequest<TParam>>), TryMapImplementationGenericArguments previously fell back to availableArguments[0] when no exact match existed. If the first candidate produced an incomplete mapping (null entries because its generic args could not be resolved to the implementation's type parameters), the caller's null check would fail and the registration was silently dropped. Fix: after the exact-match check, prefer the first candidate that produces a complete mapping (no null entries). Only fall back to availableArguments[0] when no candidate maps fully, preserving existing behavior for genuinely un-bindable registrations.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #1489 +/- ##
===========================================
+ Coverage 77.69% 77.91% +0.21%
===========================================
Files 217 217
Lines 5829 5877 +48
Branches 1253 1259 +6
===========================================
+ Hits 4529 4579 +50
+ Misses 764 760 -4
- Partials 536 538 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This was referenced Jun 17, 2026
This was referenced Jul 10, 2026
This was referenced Jul 17, 2026
This was referenced Jul 28, 2026
This was referenced Aug 4, 2026
This was referenced Aug 13, 2026
deps: Bump the all-dependencies group with 40 updates
ministryofjustice/CFO-DataManagementSystem#126
Closed
This was referenced Aug 20, 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 #1464. When an open-generic implementation implements multiple interfaces matching the registered service pattern, and the first matching interface candidate could not actually map its generic arguments to the implementation's type parameters (e.g.
IHandler<IRequest>appearing beforeIHandler<IRequest<TParam>>),TryMapImplementationGenericArgumentsreturned that broken candidate via theavailableArguments[0]fallback. The result was a valid registration being silently dropped from resolved enumerables.Fix
In
OpenGenericServiceBinder.TryMapImplementationGenericArguments, when there is no exact match, the binder now prefers the first candidate that produces a complete mapping (every implementation type parameter resolved — no null entries), falling back toavailableArguments[0]only when no candidate maps completely. This preserves prior behavior for genuinely un-bindable cases. The single-interface and exact-match paths are unchanged.The "complete mapping" check (
a.All(arg => arg is not null)) mirrors the check the caller already performs, keeping the semantics consistent.Second case (
IHandler<int>registered asIHandler<>)A type like
Handler<TParam> : IHandler<int>registered against the openIHandler<>still correctly produces no resolution result (the closedintargument leavesTParamun-inferable), with no exception and no incorrect binding — same as before the fix. If registration-time rejection of such cases is desired, that's a separate issue.Tests
Adds 4 tests in
OpenGenericMultipleInterfaceOrderTests: mappable-interface-first resolves; non-mappable-interface-first resolves (the #1464 regression); both order variants resolve from a single enumerable; and the unrelated-type-param case resolves to empty. All 155 existing open-generic tests pass.No public API changes. Zero warnings/errors; full suites pass on net8.0 and net10.0.