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.

Implementing ProtoBuf Media Formatter on an ASP.NET Core API

Custom media formatters are used for providing data exchange between client and server in a type which is not a standard media type in the likes of above. Let's see how we can implement a media formatter which enables us to have data exchange between client and server using a media called Protocol Buffers aka ProtoBuf.

Privacy Overview
Referbruv

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.

Strictly Necessary Cookies

Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.

3rd Party Cookies

This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.

Keeping this cookie enabled helps us to improve our website.