myesn

myEsn2E9

hi
github

ASP.NET Core Dependency Injection Lifecycle

  • Transient: Stateless service, such as Repository in the DAL layer
  • Scoped: Service with shared state within the scope of a request, such as Service or Controller in the BLL layer
  • Singleton: Service with shared state throughout the entire application, such as configuration classes or cache classes
    • Thread-safe, using thread-safe data structures or employing locking mechanisms in the service
    • Memory leaks, utilizing IDisposable to release resources

If uncertain about the service's state and usage scenarios, Scoped can be chosen as the default lifecycle.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.