npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@noneforge/ioc

v0.1.3

Published

A powerful and flexible dependency injection container for TypeScript with advanced features

Readme

@noneforge/ioc

Powerful, type-safe dependency injection container for TypeScript

npm version License: MIT TypeScript


View Full Documentation

Getting Started · Core Concepts · API Reference


A modern, feature-rich Dependency Injection container for TypeScript applications. Built with developer experience in mind, featuring decorators, modules, interceptors, and comprehensive testing utilities.

Features

  • Full DI Support - Constructor injection, property injection, and factory providers
  • Type-Safe - Leverages TypeScript for compile-time safety with InjectionToken<T>
  • 5 Provider Types - Class, Value, Factory, Existing (alias), and Async providers
  • 5 Scopes - Singleton, Transient, Request, Prototype, and Scoped
  • Decorator-Based - @Injectable, @Inject, @Optional, @Lazy
  • Module System - Organize code with @Module, dynamic modules, and configurable modules
  • Interceptors - Built-in caching, logging, retry, and validation interceptors
  • Testing Utilities - TestContainer with mock, spy, and snapshot support
  • AOP Decorators - @Cached, @Log, @Transactional for cross-cutting concerns
  • Lifecycle Hooks - onInit, onDestroy for resource management
  • Hierarchical Containers - Parent/child container relationships
  • Cycle Detection - Automatic circular dependency detection with Tarjan's algorithm
  • Zero Dependencies - Only requires reflect-metadata as peer dependency

Installation

npm install @noneforge/ioc reflect-metadata

Required peer dependencies:

  • reflect-metadata >= 0.2.0
  • typescript >= 5.0

TypeScript Configuration

Add to your tsconfig.json:

{
  "compilerOptions": {
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true
  }
}

Import reflect-metadata once at your application entry point:

import 'reflect-metadata';

Quick Start

Basic Usage

import 'reflect-metadata';
import { Container, Injectable, inject, InjectionToken } from '@noneforge/ioc';

// Define a service
@Injectable()
class LoggerService {
  log(message: string) {
    console.log(`[LOG] ${message}`);
  }
}

// Define another service with dependency using inject()
@Injectable()
class UserService {
  private logger = inject(LoggerService);

  createUser(name: string) {
    this.logger.log(`Creating user: ${name}`);
    
    return { id: 1, name };
  }
}

// Create container and resolve
const container = new Container();
container.addProvider(LoggerService);
container.addProvider(UserService);

const userService = container.get(UserService);
userService.createUser('John'); // [LOG] Creating user: John

Using Injection Tokens

import { InjectionToken, Container } from '@noneforge/ioc';

// Create type-safe tokens
const API_URL = new InjectionToken<string>('API_URL');
const MAX_RETRIES = new InjectionToken<number>('MAX_RETRIES');

const container = new Container();

// Register values
container.addProvider({ provide: API_URL, useValue: 'https://api.example.com' });
container.addProvider({ provide: MAX_RETRIES, useValue: 3 });

// Resolve with type safety
const apiUrl = container.get(API_URL); // string
const maxRetries = container.get(MAX_RETRIES); // number

Using Modules

import { Module, Injectable, inject, InjectionToken, bootstrap } from '@noneforge/ioc';

const CONFIG = new InjectionToken<{ apiUrl: string }>('CONFIG');

@Injectable()
class ApiService {
  private config = inject(CONFIG);

  getUrl() {
    return this.config.apiUrl;
  }
}

@Module({
  providers: [
    { provide: CONFIG, useValue: { apiUrl: 'https://api.example.com' } },
    ApiService,
  ],
  exports: [ApiService],
})
class ApiModule {}

@Module({
  imports: [ApiModule],
})
class AppModule {}

// Bootstrap the application
const { app, container } = await bootstrap(AppModule);
const apiService = container.get(ApiService);

Testing with Mocks

import { createTestContainer, createMockProvider } from '@noneforge/ioc';

// Create test container with mocks
const container = createTestContainer(
  createMockProvider(LoggerService, {
    log: vi.fn(),
  }),
  UserService,
);

const userService = container.get(UserService);
userService.createUser('Test');

// Verify mock was called
expect(container.get(LoggerService).log).toHaveBeenCalledWith('Creating user: Test');

Core Concepts

Providers

// Class Provider - instantiate a class
{ provide: MyService, useClass: MyService }

// Value Provider - use a constant value
{ provide: API_KEY, useValue: 'secret-key' }

// Factory Provider - create with dependencies
{
  provide: DatabaseConnection,
  useFactory: (config: Config) => new Database(config.dbUrl),
  inject: [Config]
}

// Existing Provider - alias to another token
{ provide: ILogger, useExisting: ConsoleLogger }

// Async Provider - async initialization
{ provide: RemoteConfig, useAsync: () => fetch('/config').then(r => r.json()) }

Scopes

@Injectable({ scope: 'singleton' })  // Default - one instance per container
class SingletonService {}

@Injectable({ scope: 'transient' })  // New instance every time
class TransientService {}

@Injectable({ scope: 'request' })    // One instance per request ID
class RequestScopedService {}

inject() Functions (Preferred)

inject(Token)              // Resolve dependency
injectOptional(Token)      // Allow null if not found
injectLazy(Token)          // Defer resolution until first access
injectAll(Token)           // Get all multi-providers

Decorators (Alternative)

@Injectable()              // Mark class as injectable
@Inject(Token)             // Specify injection token (alternative to inject())
@Optional()                // Allow null if not found (alternative to injectOptional())
@Lazy()                    // Defer resolution (alternative to injectLazy())

Documentation

Comparison with Alternatives

| Feature | @noneforge/ioc | InversifyJS | TSyringe | TypeDI | |---------|----------------|-------------|----------|--------| | Decorator-based DI | Yes | Yes | Yes | Yes | | Injection Tokens | Yes | Yes | Yes | Yes | | Module System | Yes | No | No | No | | Built-in Interceptors | Yes | No | No | No | | Testing Utilities | Yes | No | No | No | | AOP Decorators | Yes | No | No | No | | Cycle Detection | Yes | No | No | No | | Dependency Graph | Yes | No | No | No | | Request Scope | Yes | Manual | Yes | Yes | | Async Providers | Yes | Yes | Yes | Yes | | Conditional Providers | Yes | No | No | No | | EnhancedCache (LRU/LFU) | Yes | No | No | No |

Examples

See the examples directory for runnable code samples:

Requirements

  • Node.js >= 18.18.0
  • TypeScript >= 5.0
  • reflect-metadata >= 0.2.0

Contributing

Contributions are welcome! Please read the contributing guidelines before submitting a pull request.

License

MIT License - see LICENSE for details.