From the course: ASP.NET Core in .NET 6: Dependency Injection
Unlock the full course today
Join today to access over 24,700 courses taught by industry experts.
Service lifetimes - ASP.NET Core Tutorial
From the course: ASP.NET Core in .NET 6: Dependency Injection
Service lifetimes
- We're now going to look at the different Service Lifetimes independency injection. We mentioned that ASP.NET Core has a built-in DI container, and it's designed to support dependency injection. We are going to have a look at the different Service Lifetimes so that we can register the classes to the ASP.NET Core DI container classes can be registered as services with the following Service Lifetimes Singleton, Scoped, and Transient. Let's look at each one individually Singleton Service Lifetime classes are only created once per application. Once it's been created, the instance will be alive until the service is disposed of this is normally disposed of when the application stops. Just say we are selling a baseball bat for 20 dollars we would like to display this information to any customer who requests it. A Singleton Service Lifetime class can be used to store product information such as the name, and the…