class Logger {
static dependencies = ["config"] as const;
constructor(private config: string) {}
public print() {
console.log(this.config);
}
}
const container = Container
.providesValue("config", "value")
.provides(ClassInjectable("logger", Logger));
container.get("logger").print(); // prints "value"
It is recommended to use the Container.provideClass() method. The example above is equivalent to:
const container = Container
.providesValue("config", "value")
.providesClass("logger", Logger);
container.get("logger").print(); // prints "value"
Creates a reusable class Injectable whose class lookup is deferred until the Service is first resolved. The provider and the constructor it returns are memoized independently from the Service, so dependency metadata and construction always use the same class.
Creates an Injectable factory function for an InjectableClass.