Conversation
|
Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection Issue DetailsLet's look at the following example interface IBar {}
class Bar1 : IBar {}
class Bar2 : IBar {}
services.AddScoped<IBar, Bar1>(); // Slot: 1
services.AddTransient<IBar, Bar2>(); // Slot: 0
var sp = services.BuildServiceProvider(validateScopes: true);
Debug.Assert(sp.GetService<IBar>() is Bar2)The last implementation will be resolved by convention. For more details see the
|
|
|
||
| private static ServiceCacheKey GetCacheKey(ServiceCallSite callSite) | ||
| { | ||
| return callSite.Cache.Key.Equals(ServiceCacheKey.Empty) |
There was a problem hiding this comment.
The call to callSite.Cache.Key should only ever occur once for perf.
| { | ||
| OnResolve(callSite, scope); | ||
| DependencyInjectionEventSource.Log.ServiceResolved(this, serviceType); | ||
| return realizedService.Invoke(scope); |
There was a problem hiding this comment.
.Invoke() is unnecessary.
| } | ||
|
|
||
| [Fact] | ||
| public void ScopeValidation_ShouldBeAbleToDistingushGenericCollections_WhenGetServiceIsCalledOnRoot() |
There was a problem hiding this comment.
It appears this passes without the changes here. Is that intentional?
There was a problem hiding this comment.
Yes, It is intentional. It tests the GetCacheKey() private method that replaces ResultCache.None for services. (For instance, IEnumerable<Foo> and IEnumerable<Bar> have the same ResultCache that is equal to ResultCache.None if at least one of the Foo and at least one of the Bar have transient lifetime)
Please add a corresponding issue and link to it from this PR. Thanks |
|
Fix #87429 |
|
Failure on runtime known issue. |
|
Thanks @mapogolions |
Fixes #87429
Let's look at the following example
The last implementation will be resolved by convention. For more details see the
CallSiteFactoryclass and theDefaultSlotproperty. The scope validation is fine with a service lifetime (GetService for Transient service on the Root scope).But the behavior breaks when we set the
ValidateOnBuildproperty to 'true'. Please see unit tests that reproduce the issue.