import "@ipare/core"; import { Context, ObjectConstructor, Startup } from "@ipare/core"; declare module "@ipare/core" { interface Startup { expectInject( key: string, fn: (service: T, ctx: Context) => void | Promise ): this; expectInject( service: ObjectConstructor, fn: (service: T, ctx: Context) => void | Promise ): this; } } Startup.prototype.expectInject = function ( service: ObjectConstructor | string, fn: (service: T, ctx: Context) => void | Promise ) { return this.use(async (ctx, next) => { await next(); const parseInject = getDepFunc< (ctx: Context, service: any) => Promise >("@ipare/inject", "parseInject"); const sv = await parseInject(ctx, service as any); if (!sv) throw new Error("Create service failed"); await fn(sv, ctx); }); }; function getDepFunc(depName: string, funcName: string): T { // eslint-disable-next-line @typescript-eslint/no-var-requires const d = require(depName); return d[funcName] as T; }