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

@typewirets/inversify

v0.1.0

Published

InversifyJS adapter for TypeWire dependency injection

Readme

TypeWire Inversify Adapter

The InversifyJS adapter for TypeWire, allowing you to use TypeWire with InversifyJS containers.

Installation

npm install @typewirets/inversify inversify

Usage

The adapter allows you to use TypeWire definitions with an existing InversifyJS container:

import { Container } from 'inversify';
import { createInversifyAdapter } from '@typewirets/inversify';
import { typeWireOf } from '@typewirets/core';

// Define your services
class Logger {
  log(message: string): void {
    console.log(`[LOG] ${message}`);
  }
}

class UserService {
  constructor(private logger: Logger) {}

  getUser(id: string): void {
    this.logger.log(`Getting user with id: ${id}`);
    // Implementation...
  }
}

// Create an Inversify container
const container = new Container();

// Create an adapter to use with TypeWire
const adapter = createInversifyAdapter(container);

// Create TypeWire definitions
const loggerWire = typeWireOf({
  token: 'Logger',
  creator: () => new Logger()
});

const userServiceWire = typeWireOf({
  token: 'UserService',
  creator: (ctx) => new UserService(loggerWire.getInstance(ctx))
});

// Register with the Inversify container (using async/await)
async function setup() {
  await loggerWire.apply(adapter);
  await userServiceWire.apply(adapter);
  
  // Resolve using the TypeWire API
  const userService = userServiceWire.getInstance(adapter);
  userService.getUser('123');
}

setup();

Using with Existing Inversify Code

You can also use TypeWire alongside existing Inversify bindings:

import { Container, injectable, inject } from 'inversify';
import { createInversifyAdapter, adaptToResolutionContext } from '@typewirets/inversify';
import { typeWireOf, typedSymbolOf } from '@typewirets/core';

// Existing Inversify setup
const TYPES = {
  Database: Symbol.for('Database')
};

@injectable()
class Database {
  connect() { /* ... */ }
}

// TypeWire definition
const loggerWire = typeWireOf({
  token: 'Logger',
  creator: () => new Logger()
});

// Hybrid service that uses both
const userRepoWire = typeWireOf({
  token: 'UserRepository',
  creator: (ctx) => {
    // Get TypeWire dependency
    const logger = loggerWire.getInstance(ctx);
    
    // Get Inversify dependency (through the adapter)
    const db = ctx.get(typedSymbolOf('Database'));
    
    return new UserRepository(logger, db);
  }
});

// Setup (using async/await)
async function setup() {
  const container = new Container();
  container.bind(TYPES.Database).to(Database).inSingletonScope();

  const adapter = createInversifyAdapter(container);
  await loggerWire.apply(adapter);
  await userRepoWire.apply(adapter);
  
  // Use the repository
  const repo = userRepoWire.getInstance(adapter);
}

setup();

Adapter Functions

The adapter provides three main functions:

adaptToResolutionContext

Creates a TypeWire ResolutionContext adapter for an Inversify container:

import { adaptToResolutionContext } from '@typewirets/inversify';

const resolutionContext = adaptToResolutionContext(container);
const logger = loggerWire.getInstance(resolutionContext);

adaptToBindingContext

Creates a TypeWire BindingContext adapter for an Inversify container:

import { adaptToBindingContext } from '@typewirets/inversify';

const bindingContext = adaptToBindingContext(container);
await loggerWire.apply(bindingContext);  // Note the await

createInversifyAdapter

Creates a combined adapter that implements both ResolutionContext and BindingContext:

import { createInversifyAdapter } from '@typewirets/inversify';

const adapter = createInversifyAdapter(container);
await loggerWire.apply(adapter);  // Note the await
const logger = loggerWire.getInstance(adapter);

Scope Mapping and Behavior

The adapter automatically maps TypeWire scopes to Inversify binding scopes:

| TypeWire Scope | Inversify Scope | |----------------|-------------------| | 'singleton' | 'Singleton' | | 'transient' | 'Transient' | | 'request' | 'Request' |

Important Notes About Scoping:

  • Singleton and Transient Scopes: These work as expected in all scenarios and are the recommended scopes to use with TypeWire. See the core package documentation for more details on our recommended scoping strategy.

  • Request Scope: While supported for compatibility, this requires special attention:

    • Request scope in Inversify is designed to work with container hierarchies
    • For request scope to work correctly, you must:
      1. Use Inversify's container hierarchy properly (typically with a parent container and child containers per request)
      2. Ensure your components using request-scoped dependencies are managed by Inversify (usually with @injectable() decorators)
    • In standalone applications (non-web) or when not using container hierarchies, request scope may behave like transient scope
    • We generally recommend using singleton scopes with explicit parameter passing instead of relying on request scopes

License

MIT