Dependency Injection Lifetime..How to Use AddScoped,AddTransient,AddSingleton in ASP NET CORE 6.0



Dependency Injection Lifetime..How to Use AddScoped,AddTransient,AddSingleton in ASP NET CORE 6.0

Dependency Injection Lifetime..How to Use AddScoped,AddTransient,AddSingleton in ASP NET CORE 6.0

Dependency Injection Lifetime..How to Use AddScoped,AddTransient,AddSingleton in ASP NET CORE 6.0

Dependency injection is the technique of providing an object its dependencies (which are nothing but other objects) instead of having it construct them itself. It helps us adhere to the Inversion of Control (IoC) design principle more easily. We have discussed this concept in detail in our Dependency Injection in ASP.NET Core video https://www.youtube.com/watch?v=791Odt_5_h8&t=277s.

We’ve mentioned different ways in which we can register the dependencies based on what lifetime we require for them. Let’s refresh our memories on the different registration lifetimes available in .NET Core:

Transient – created each time they’re requested from the service container
Scoped – created once per client request and is reused within that request
Singleton – created only once and is reused across the application’s lifetime

Subscribe to our channel: https://youtube.com/@MacroCoding?sub_confirmation=1

Comments are closed.