dn-ioc
v0.3.1
Published
A lightweight, type-safe Inversion of Control (IoC) dependency injection library for TypeScript, built with a functional programming paradigm.
Maintainers
Readme
dn-ioc
dn-ioc is a small TypeScript dependency-injection kernel. A provider is a factory. provide() makes a Ref with a default factory. token() makes a key that must be bound. inject() resolves either one. There is no container, no decorators, and no reflection.
It does not provide modules, request-scoped containers, multi-bindings, or runtime signal listeners.
Documentation: https://dn-ioc.lyz.cloud/
Install
npm install dn-ioc
pnpm add dn-ioc
yarn add dn-ioc
bun add dn-ioc
deno add npm:dn-iocDeno can also import npm:dn-ioc without installing. The package is ESM-only.
Start
import { bootstrapApp, provide } from 'dn-ioc'
const configRef = provide(() => ({ greeting: 'hello' }))
const greeterRef = provide(({ inject }) => {
const config = inject(configRef)
return { greet: (name: string) => `${config.greeting}, ${name}` }
})
const app = bootstrapApp(({ inject }) => {
console.log(inject(greeterRef).greet('world')) // hello, world
})
await app.start()This graph holds no resources, so it does not need stop(). Scopes, cleanup, async factories, and the public API are in the docs.
Development
Bun 1.4.3. bun test --coverage exits 0 below 100%, so bun run test is the test run and the coverage gate together. bun check fails on type errors, so that is bun run type-check.
bun install
bun run test
bun run type-check
bun run lint
bun run build