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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.