.Net Core এ Dependency Injection (Transient, Scoped, Singleton) কিভাবে কাজ করে?



.Net Core এ Dependency Injection (Transient, Scoped, Singleton) কিভাবে কাজ করে?

.Net Core এ Dependency Injection (Transient, Scoped, Singleton) কিভাবে কাজ করে?

In ASP.NET Core, the concept of scope refers to the lifetime and availability of objects and services within the application. There are three main types of scope commonly used in ASP.NET Core:

Transient Scope ;
– Transient scope objects are created each time they are requested from the service container.
– Each request for a transient object will result in a new instance being created.
– Transient objects are not shared across different parts of the application.

Scoped Scope:
– Scoped scope objects are created once per scope.
– A scope is typically associated with a single HTTP request in an ASP.NET Core application.
– The same instance is shared within the same scope, but different scopes will have different instances.

Singleton Scope:
– Singleton scope objects are created only once and shared across the entire application.
– The same instance is used every time an object of that type is requested.
– Singleton objects are shared across all parts of the application, including different HTTP requests and different users.