Skip to content

aulisius/syringe

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published