Value dependencies

Static values can be registered with context.setValue():

context.setValue(new Service());

@injectable({ inject: [ Service ] })
class Component {
public constructor(service: Service) {}
}

Any kind of value can be registered but usually you want to inject it as a named dependency when the value has no unique type:

context.setValue(12345, "secret-code");

@injectable({ inject: [ "secret-code" ] })
class Luggage {
public constructor(combination: number) {}
}

Asynchronous values can be registered as a promise but can only be injected by name:

context.setValue(Promise.resolve({ verbose: true }), "config");

@injectable({ inject: [ "config" ] })
class Component{
public constructor(config: Config) {
if (config.verbose) {
console.log("Component created");
}
}
}

If you want to inject an asynchronous value by type then you have to register a factory function instead.