Wednesday, November 21, 2018

Types of dependency Injection lifetime dependency Injection


We define the lifetime when we register the service.
There are three ways, by which you can do that, which in turn decides how the lifecycle of the services are managed.
  1. Transient: New instance is created, every time you create a service
  2. Scoped: New instance is generated for every scope. ( Each request is a Scope). Within the scope, service is reused.
  3. Singleton: Service is created only once, and used everywhere.

Register the Transient Service

Now, under ConfigureServices method of the startup class register the SomeServive via ITransientServiceinterface as shown below.

https://www.tektutorialshub.com/dependency-injection-lifetime-transient-singleton-scoped/

No comments:

Followers

Link