Skip to content

What is the lifetime of IServiceScopeFactory and IServiceProvider ? #31478

@EnricoMassone

Description

@EnricoMassone

I'm looking for some informations related to the lifetime of IServiceScopeFactory and IServiceProvider when they are injected inside of a custom service, an MVC controller or an hosted service.

Based on my understanding, IServiceScopeFactory is automatically registered with the dependency injection system as a singleton service. Is my understanding correct ?

My doubt are related to the injection of IServiceProvider, because there is a root service provider and several children service providers (one per each scope defined when an HTTP request is handled by the ASP.NET core application).

When I request an instance of IServiceProvider from the constructor of an MVC controller do I get the root container or a child container for the scope of the current HTTP request ?

What about the injection of IServiceProvider in the constructor of an hosted service ? In that case the root container is inject, right ?

Thanks for helping.

Enrico.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions