A tiny dependency injection solution written in JS
npm install @faizaanceg/syringe
yarn add @faizaanceg/syringe
import { Syringe } from "@faizaanceg/syringe";
const injections = [
{ name: "host", uses: [], injectFn: () => "https://example.com" },
{
name: "endpoints",
uses: [{ name: "host" }],
injectFn: ({ host }) => ({ url: host + "/" }),
},
];
Syringe.fill(injections);
console.log(Syringe.inject("endpoints")); // { url: "https://example.com/" }
console.log(Syringe.inject("host")); // "https://example.com"
fill
method is used to setup the injections that'll be later requested by your app.
fill(injections: Injections[]): void
inject
method is used to inject the dependency wherever requested.
inject(name: string): T