A base class that can be extended to produce a TypeKey<T>
class object.
class NameKey extends TypeKey<string>() { private _: any }
with Scope:
class NameKey extends TypeKey<string>() {
private _: any
static scope = Singleton
}
with default instance:
class NameKey extends TypeKey({ default: Inject.value('Alice') }) {
private _: any
}
with custom default:
class NameKey extends TypeKey({
default: Inject.map(DataSource, ds => ds.getName()),
}) {
private _: any
}
using the TypeKey
:
const ct = Container.create().provide(NameKey, () => 'Alice')
const name: string = ct.request(NameKey)
const UserModule = Module(ct => ct
.provide(User, { name: NameKey }, ({ name }) => new User(name))
)
const UserModule = Module(ct => ct
.provide(User, { name: NameKey.Lazy() }, ({ name }) => new User(name()))
)
Generated using TypeDoc
Generates a base class for a class object that extends TypeKey<T>. Classes that extend the returned base class should have a
private _: any
property (or any other private member) to ensure the key has its own unique type.