Skip to content

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

Closed
@mapogolions

Description

@mapogolions

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions