This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.
How do you register services?
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.
What is meant by a service?
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.