Skip to content

georgyfarniev/fpdi

Repository files navigation

FPDI - minimalistic dependency injection module

Mission: build convenient and lightweight dependency injection library.

Why FPDI?

  • No dependencies
  • No requirements to use unsopported language features such as decorators
  • Framework and language agnostic (both Typescript and Javascript supported)
  • Typescript support (optional)
  • Convenience and simplicity (inspired by react hooks)
  • Throwing exception if your dependency not found or same dependency overriden (can be disabled)

Examples

Typescript

import fpdi from 'fpdi'

fpdi.provide('db', 'Database instance')
fpdi.provide('constant', 3.14)

const [ db, constant ] = fpdi.inject<string, number>('db', 'constant')

Javascript

const fpdi = require('fpdi')

fpdi.provide('db', 'Database instance')
fpdi.provide('constant', 3.14)

// Line below use type annotation for returned array. Works at least in vscode

/** @type {[string, number]} */
const [ db, constant ] = fpdi.inject('db', 'constant')

Bigger example stored in /src/examples/basic.ts

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published