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

@notjustcoders/ioc-arise

v1.1.32

Published

Arise type-safe IoC containers from your code. Zero overhead, zero coupling.

Downloads

242

Readme

IoC Arise

A command-line tool that automatically generates type-safe IoC (Inversion of Control) containers for TypeScript projects using the ioc-arise runtime library. It analyzes your classes, detects dependencies, and generates the necessary registration code.

Table of Contents

Features

  • 🔍 Automatic Detection: Finds classes, factory functions, and value objects to register
  • 🧠 Dependency Analysis: Parses constructor and function dependencies from TypeScript code
  • 🛡️ Type Safety: Uses the type-safe ioc-arise runtime library
  • 🚫 No Decorators: Pure static analysis, no runtime decorators required
  • ⚠️ Circular Dependency Detection: Warns about dependency cycles
  • 🏭 Factory Functions: Supports @factory-annotated functions with separate params or context object pattern
  • 🔌 Instance Factories: Functions with an explicit interface return type automatically act as implementation providers for that interface
  • 💎 Value Objects: Supports @value-annotated constants registered with useValue
  • 📦 Modular Containers: Generates per-module files with ContainerModule for large projects
  • 🌐 External Package Types: Constructor and factory parameters typed with interfaces from external npm packages or sibling monorepo packages are correctly resolved using the TypeScript symbol name as the DI token

Installation

First, install the runtime library and the CLI:

# Install runtime library
npm install ioc-arise

# Install CLI globally
npm install -g @notjustcoders/ioc-arise

# Or use with npx
npx @notjustcoders/ioc-arise --help

Usage

# Basic usage
ioc-arise generate

# With custom source and output
ioc-arise generate --source src --output src/container.gen.ts

Configuration File

You can create an ioc.config.json file in the same directory as your source code to set default options. CLI arguments will override config file settings.

{
  "source": "src",
  "output": "container.gen.ts",
  "interface": "I[A-Z].*",
  "exclude": [
    "**/*.test.ts",
    "**/*.spec.ts",
    "**/node_modules/**"
  ],
  "checkCycles": false,
  "verbose": true
}

Config File Location

The config file should be placed in the same directory as your source code. For example, if your source directory is src, place ioc.config.json in the src directory.

Priority Order

  1. CLI arguments (highest priority)
  2. Config file settings
  3. Default values (lowest priority)

Examples

Basic Example

Directory structure:

minimal-todo/
├── entities/Todo.ts
├── repositories/
│   ├── ITodoRepository.ts
│   └── InMemoryTodoRepository.ts
├── services/
│   ├── ITodoService.ts
│   └── TodoService.ts
├── ioc.config.json
└── container.gen.ts (generated)

Generated container (container.gen.ts):

/**
 * This file is auto-generated by ioc-arise.
 * Do not modify this file manually.
 */
import { Container, Lifecycle } from '@notjustcoders/di-container';
import { InMemoryTodoRepository } from './repositories/InMemoryTodoRepository';
import { TodoService } from './services/TodoService';

export const container = new Container();

container.register(InMemoryTodoRepository, {
  useClass: InMemoryTodoRepository,
  lifecycle: Lifecycle.Singleton,
});

container.register(TodoService, {
  useClass: TodoService,
  dependencies: [InMemoryTodoRepository],
  lifecycle: Lifecycle.Transient,
});

Instance Factories

An instance factory is any exported function whose explicit return type annotation resolves to a registered interface. No @factory annotation is needed — the return type is the signal. The function is registered under the interface name as the token (just like a class that implements the interface).

Separate params:

// repositories/createUserRepository.ts
import { IAppConfig } from '../config/IAppConfig';
import { ILogger } from '../logger/ILogger';
import { IUserRepository } from './IUserRepository';

export function createUserRepository(
  config: IAppConfig,
  logger: ILogger,
): IUserRepository {
  if (config.getStorageType() === 'persistent') {
    logger.info('Using persistent storage');
    return new PersistentUserRepository(config.getDbPath());
  }
  logger.info('Using in-memory storage');
  return new InMemoryUserRepository();
}

Generated registration:

container.register('IUserRepository', {
  useFactory: createUserRepository,
  dependencies: ['IAppConfig', 'ILogger'],
  lifecycle: Lifecycle.Singleton,
});

Context object:

// repositories/createUserRepository.ts
export function createUserRepository(
  context: { config: IAppConfig; logger: ILogger },
): IUserRepository {
  const { config, logger } = context;
  if (config.getStorageType() === 'persistent') {
    logger.info('Using persistent storage');
    return new PersistentUserRepository(config.getDbPath());
  }
  logger.info('Using in-memory storage');
  return new InMemoryUserRepository();
}

Generated registration:

container.register('IUserRepository', {
  useFactory: (config, logger) => createUserRepository({ config, logger }),
  dependencies: ['IAppConfig', 'ILogger'],
  lifecycle: Lifecycle.Singleton,
});

Uniqueness rule: an interface can have at most one implementation provider — either a class that implements it, or an instance factory that returns it. Registering both throws an error at generation time.

External & Monorepo Types

Dependencies typed with interfaces from external npm packages or sibling monorepo packages are fully supported. The TypeScript symbol name is used as the DI token — the same convention as for local interfaces.

Shape 1 — Direct external import:

// services/OrderService.ts
import type { IPaymentGateway } from '@payments/sdk';
import type { IOrderService } from './IOrderService';

export class OrderService implements IOrderService {
  constructor(private gateway: IPaymentGateway) {}
}

Generated registration:

container.register('IOrderService', {
  useClass: OrderService,
  dependencies: ['IPaymentGateway'],
  lifecycle: Lifecycle.Singleton,
});

Shape 2 — Local re-export stub (common monorepo pattern):

// src/ports/ITombstoneRepository.ts — re-export stub
export type { ITombstoneRepository } from '@word-tracker/sync';

// src/PermanentlyDeleteWordUseCase.ts — factory using it
import type { IWordEntryRepository } from './IWordEntryRepository';        // local
import type { ITombstoneRepository } from './ports/ITombstoneRepository';  // re-export stub

/** @factory */
export function createPermanentlyDeleteWordUseCase(deps: {
  wordEntryRepository: IWordEntryRepository;
  tombstoneRepository: ITombstoneRepository;
}) { ... }

Generated registration:

container.register('createPermanentlyDeleteWordUseCase', {
  useFactory: (wordEntryRepository, tombstoneRepository) =>
    createPermanentlyDeleteWordUseCase({ wordEntryRepository, tombstoneRepository }),
  dependencies: ['IWordEntryRepository', 'ITombstoneRepository'],
});

The token for the external type (ITombstoneRepository) is the TypeScript symbol name. You are responsible for registering a concrete implementation under that token elsewhere (e.g., in another module).

Usage in Your Code

import { container } from './container.gen';
import { TodoService } from './services/TodoService';

// Resolve dependencies
const todoService = container.resolve(TodoService);
const todos = await todoService.getAllTodos();

Development

# Run in development mode
pnpm run dev

# Build for production
pnpm run build

Limitations

  • Constructor parameters typed with non-interface types (e.g., concrete classes from external packages) are not auto-resolved
  • Circular dependencies are detected and warned about
  • Only analyzes TypeScript files (.ts extension)

Contributing

Contributions are welcome! Please feel free to submit issues and pull requests.