All packages
npm package

@pyriter/anchorjs

Decorator-based dependency injection for Node.js.

Version v3.3.0
Weekly 163
License OSS

Installation

$ npm install @pyriter/anchorjs
$ pnpm add @pyriter/anchorjs
$ yarn add @pyriter/anchorjs
$ bun add @pyriter/anchorjs

Overview

A small, opinionated dependency-injection container for TypeScript. Wire services together with `@Injectable` and resolve them out of a single root container — no decorators metadata gymnastics, no runtime surprises.

  • Decorator API (@Injectable, @Inject) on top of standard TypeScript
  • Singleton, transient, and scoped lifetimes
  • Works in Node, AWS Lambda, and serverless runtimes
  • Zero runtime dependencies

Usage

Define an injectable service

ts
import { Injectable } from '@pyriter/anchorjs';

@Injectable()
export class UserRepository {
  findById(id: string) {
    return { id, name: 'Ada Lovelace' };
  }
}

Resolve from the container

ts
import { Anchor } from '@pyriter/anchorjs';
import { UserRepository } from './user-repository';

const repo = Anchor.resolve(UserRepository);
const user = repo.findById('42');

Keywords

dependency injectionIoCTypeScriptNode.js