Service providers

The records added to injectors are called service providers, or simply providers. They specify two sets of information:

  • Which requests are resolved by the service?
  • How to create an instance of the service?

More specifically, providers have one of the following formats:

{provide: <token>, useClass: <class name>}{provide: <token>, useFactory: <function>, deps: [<dependency>,..]}{provide: <token>, useValue: <object or simple type instance>}

The token property specifies the kind of requests the provider is able to satisfy. Often, it is a class name, in which case the service is selected when this class name is identical to the type of the constructor parameter where the service must be injected:

{provide: ProductServerCommunicatior ...

Get Hands-On TypeScript for C# and .NET Core Developers now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.