@faizaanceg/syringe
v0.1.1
Published
A tiny dependency injection solution
Downloads
18
Maintainers
Readme
@faizaanceg/syringe
A tiny dependency injection solution written in JS
Installation
npm install @faizaanceg/syringe
yarn add @faizaanceg/syringe
Usage
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"
API
fill
fill
method is used to setup the injections that'll be later requested by your app.
Signature
fill(injections: Injections[]): void
inject
inject
method is used to inject the dependency wherever requested.
Signature
inject(name: string): T