How Does Life Cycle Dependency Injection Work?

Asked

Viewed 362 times

2

How the 3 life cycles of a dependency injection works such as Singleton, Transient and Scope ?

1 answer

2


Singleton : A service object is created and provided for all requests. Thus, all requests get the same object;

Transient : will always generate a new instance for each found item that has such a dependency, that is, if there are 5 dependencies there will be 5 different instances

scoped : this one different from Transient that ensures that in a request an instance of a class is created where if there are other dependencies, be used this single instance for all, renewing only in the subsequent requests, but, maintaining this obligation.

  • Eduardo after all what is the difference between scoped and Transient? so I understood the object of the service is created for each request?

  • @Thiagoloureiro found a better definition

  • 1

    Now yes! + 1! Thanks for the clarification!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.