/net-core-dependency-injection-object-lifetime

In .NET Core, you can register dependencies using three different methods AddSingleton, AddTransient, and AddScoped. This blog explains each of these methods.

Primary LanguageC#

.NET Core Dependency Injection Object Lifetime

In .NET Core, you can register dependencies using three different methods AddSingleton, AddTransient, and AddScoped. This blog explains each of these methods.

Objects injected using Dependency Injection have a specific lifetime. Object's lifetime depends on how you register dependency. To understand how each method is different from than others we will create a console application, and service and inject this service to application middleware.

  1. AddSingleton

  2. AddTransient

    .NET Core Dependency Injection Transient Instance

  3. AddScoped

    .NET Core Dependency Injection Scoped Instance

For more information please visit https://geeksarray.com/blog/net-core-dependency-injection-object-lifetime