Commit 2a337319 authored by nanahira's avatar nanahira

support get lazy

parent 87514e32
......@@ -189,11 +189,24 @@ export class AppContextCore<Cur = Empty, Req = Empty> {
return this as any;
}
get<R>(cls: AppServiceClass<Cur, Req, any, R>): R {
const key = cls as unknown as AnyClass;
get<R>(
cls:
| AppServiceClass<Cur, Req, any, R>
| (() => AppServiceClass<Cur, Req, any, R>),
): R {
let key = cls as unknown as AnyClass;
if (
!this.registry.has(key) &&
typeof cls === 'function' &&
!(cls as any).prototype
) {
key = (cls as () => AppServiceClass<Cur, Req, any, R>)() as AnyClass;
}
if (!this.registry.has(key)) {
throw new Error(`Service not provided: ${cls.name}`);
throw new Error(`Service not provided: ${key?.name ?? cls.name}`);
}
const entry = this.registry.get(key)!;
const inst = entry.inst;
if (isPromiseLike(inst)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment