Skip to content

Why I can inject Scoped service into BackgroundService if not in development environment? #109491

Answered by davidfowl
kklldog asked this question in Q&A
Discussion options

You must be logged in to vote

The scope service check only happens in development, originally it was done that way to save on performance at runtime and avoid breaking changes but maybe its time to always do scope validation by default. There is no scope when you inject into a background thread, its a singleton so the "scope" is top level.

See https://ankitvijay.net/2020/03/17/net-core-and-di-beware-of-captive-dependency/

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@kklldog
Comment options

@lilinus
Comment options

@julealgon
Comment options

@kklldog
Comment options

@kklldog
Comment options

Answer selected by kklldog
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
untriaged New issue has not been triaged by the area owner area-Extensions-DependencyInjection
4 participants
Converted from issue

This discussion was converted from issue #109490 on November 03, 2024 15:45.