Building a dependency injector

In this section of the chapter, we will use the learnings we have gained in writing a service locator and combine this with TypeScript decorators in order to create a simple dependency injection framework. Before we do, however, let's discuss the problem of interface resolution.

Interface resolution

As we know, the interface keyword is a TypeScript language construct that we use to define the shape of classes or objects. Wherever we need to define a custom type, and need the TypeScript compiler to ensure that properties and functions are available on an object, we use an interface. Interfaces are particularly handy when describing services, where any number of services could provide the same functionality to our code. ...

Get Mastering TypeScript - Second Edition now with O’Reilly online learning.

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