Dependency injection in MobX

In the preceding section, we decorated the ActorStore class with the @provide decorators:

@provide(TYPE.ActorStore) 
export class ActorStore implements interfaces.ActorStore { 

This decorator is an alternative to the InversifyJS biding syntax and is equivalent to the following:

container.bind<ActorStore>(TYPE.ActorStore).to(ActorStore); 

The @provide decorator is not required but it is more convenient than the binding API. The @provide decorator can be created using the inversify-binding-decorators module as follows:

import { Container } from "inversify"; import { makeProvideDecorator } from "inversify-binding-decorators"; const container = new Container(); const provide = makeProvideDecorator(container); export ...

Get Learning TypeScript 2.x - Second Edition 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.