0.1.1 • Published 5 days ago

@faizaanceg/syringe v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 days ago

@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
0.1.1

5 days ago

0.1.0

5 days ago

0.0.1

11 months ago