Skip to content
This repository has been archived by the owner on Aug 22, 2023. It is now read-only.

galatajs/inject

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


@galatajs/inject

Dependency Injection package of galatajs framework.

What Is It?

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.

Installation

npm install @galatajs/inject

or with yarn

yarn add @galatajs/inject

Usage With Global Provider

// 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.

Usage With Custom Types

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")