Dependency Injection package of galatajs framework.
This package is the inject package of the galatajs framework.
With this package, you can provide some values that you will reuse to inject later.
You don't have to use galatajs framework, @galatajs/inject is a nodejs package.
npm install @galatajs/injector with yarn
yarn add @galatajs/inject
// main.ts
import { provide } from "@galatajs/inject"
const logger = (...msg: any[]) => {
console.log(...msg);
}
provide("logger", logger);
provide("city", "galatajs")
provide("population", 15600000)// anything.ts
import { inject } from "@galatajs/inject"
const logger = inject("logger")
const city = inject("city")
const population = inject("population")
logger("Hello, ", city, " has ", population, " people.")
// Hello, galatajs has 15600000 people.import { createInjector } from "@galatajs/inject"
type Product = {
name: string
price: number
}
const productInjector = createInjector<Product>();
productInjector.provide("product", {
name: "iPhone X",
price: 999999
});
const iphoneX = productInjector.inject("product")