Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Service Provider cannot resolve transient service from the Root scope if the ValidateOnBuild option is enabled #87429

Closed
mapogolions opened this issue Jun 12, 2023 · 1 comment · Fixed by #87354

Comments

@mapogolions
Copy link
Contributor

mapogolions commented Jun 12, 2023

Description

Service Provider cannot resolve transient service from the Root scope if the ValidateOnBuild option is enabled.

Reproduction Steps

interface IBar {}
class Bar1 : IBar {}
class Bar2 : IBar {}

services.AddScoped<IBar, Bar1>();
services.AddTransient<IBar, Bar2>();

var sp = services.BuildServiceProvider(new ServiceProviderOptions { ValidateScopes = true, ValidateOnBuild = true });

Expected behavior

Debug.Assert(sp.GetService<IBar>() is Bar2)

Actual behavior

Thrown Exception

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jun 12, 2023
@ghost
Copy link

ghost commented Jun 12, 2023

Tagging subscribers to this area: @dotnet/area-extensions-dependencyinjection
See info in area-owners.md if you want to be subscribed.

Issue Details

Description

Service Provider cannot resolve transient service from the Root scope if the ValidateOnBuild option is enabled.

Reproduction Steps

interface IBar {}
class Bar1 : IBar {}
class Bar2 : IBar {}

services.AddScoped<IBar, Bar1>();
services.AddTransient<IBar, Bar2>();

var sp = services.BuildServiceProvider(new ServiceProviderOptions { ValidateScopes = true, ValidateOnBuild = true });
Debug.Assert(sp.GetService<IBar>() is Bar2)

Expected behavior

Debug.Assert(sp.GetService() is Bar2)

Actual behavior

Thrown Exception

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Author: mapogolions
Assignees: -
Labels:

area-Extensions-DependencyInjection

Milestone: -

@steveharter steveharter added bug and removed untriaged New issue has not been triaged by the area owner labels Jun 13, 2023
@steveharter steveharter added this to the 8.0.0 milestone Jun 13, 2023
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jun 28, 2023
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jun 28, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Jul 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants