Blazor University Learn the .NET SPA framework from Microsoft
Ctrl X

I am available for contract work, contact me via Linked-in or Email.

Dependency lifetimes and scopes

Two important questions to ask when using dependency injection are: How long will the instances of these dependencies live, and how many other objects have access to the same instance?

The answer depends on a number of factors, mainly because different options have been made available to us so that we can make the decision for ourselves. The first factor, and possibly the easiest to understand, is the Scope the dependency was registered with. The scopes defined by Microsoft.Extensions.DependencyInjection.ServiceLifetime are Singleton, Scoped, and Transient.