@joist/di
Version:
Dependency Injection for Vanilla JS classes
17 lines • 676 B
JavaScript
import { readInjector } from "./metadata.js";
export function inject(token, opts) {
return internalInject((i) => i.inject(token, opts));
}
export function injectAll(token, opts) {
return internalInject((i) => i.injectAll(token, opts));
}
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