UNPKG

@joist/di

Version:

Dependency Injection for Vanilla JS classes

17 lines 652 B
import { readInjector } from "./metadata.js"; export function inject(token) { return internalInject((i) => i.inject(token)); } export function injectAll(token) { return internalInject((i) => i.injectAll(token)); } function internalInject(cb) { return function () { const injector = readInjector(this); if (injector === null) { throw new Error(`${this.constructor.name} is either not injectable or a service is being called in the constructor. \n Either add the @injectable() to your class or use the @injected callback method.`); } return cb(injector); }; } //# sourceMappingURL=inject.js.map