What are service lifetimes in ASP.NET Core?
A service lifetime defines how a service instance is maintained or created by the container when requested for a new instance.
A class can be registered as a service by adding it to the IServiceCollection instance under the ConfigureServices() method in the Startup class.
A class MyClass can be registered as a service in the below ways:
services.AddT<MyClass>(new MyClass()); (or)
services.AddT<new MyClass());
services.AddT<IMyClass, MyClass>(); (or)
services.AddT<IMyClass>(new MyClass());
Where T can be Singleton, Transient or Scoped.
A service is an interface which is resolved for a configured concrete implementation with a specified lifetime, which is managed by the IoC container and is injected via constructor or method whenever requested by the calling method or class.
It is configured using the ConfigureServices() method in the Startup class.