Skip to content

Instantly share code, notes, and snippets.

@wzhudev
Last active September 16, 2021 12:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wzhudev/9297610736ecb083b08636282d251d48 to your computer and use it in GitHub Desktop.
Save wzhudev/9297610736ecb083b08636282d251d48 to your computer and use it in GitHub Desktop.
JavaScript dependency injection (DI) libraries

Compilation + Runtime

Runtime

Implementations based on reflect-metadata

Implementations not based on reflect-metadata

A benefit of using reflect-metadata is that you don't have to declare dependency for classes.

Say

@Injectable
class A {
  constructor(private readonly b: B) {}
}

The injector will know that A depends on B.

Compare to

class A {
  constructor(@Need(B) private readonly: B) {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment