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.
- Transient: New instance is created, every time you create a service
- Scoped: New instance is generated for every scope. ( Each request is a Scope). Within the scope, service is reused.
- 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.
No comments:
Post a Comment