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.

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.


Buy Me A Coffee

Found this article helpful? Please consider supporting!

Ram
Ram

I'm a full-stack developer and a software enthusiast who likes to play around with cloud and tech stack out of curiosity. You can connect with me on Medium, Twitter or LinkedIn.

Leave a Reply

Your email address will not be published. Required fields are marked *