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

microdi2

v0.1.0

Published

MicroDI Typescript library

Readme

Micro Dependency injection library

The problem

First, let's imagine we have such classes, one depends on another one.

// IA.ts
export interface A {
  a(): string;
}

// A.ts
import type { IA } from "./IA";

export class A implements IA {
  public a(): string {
    return "A";
  }
}

// IB.ts
export interface IB {
  b(): string;
}

// B.ts
import type { IA } from "./IA";
import type { IB } from "./IB";

export class B implements IB {
  public constructor(private readonly a: IA) {}

  public b() {
    return "B";
  }
}

All of them must be instantiated, so we'll apply this logic to do that:

export const instanceB = new B(new A());

Looks simple, right? But when a class has a lot of dependencies and Its dependencies has their own dependencies (and so on), the instantiation logic might be very complicated:

const app = new App(new Router(), new Authorization(new HttpClient(new UserService)), new Whatever(), ...);

Simple? Not quite.

The solution

We may have a container that resolves our dependencies (and event instantiate classes on demand):

// container.ts
// Container has been initialized internally:
import { initContainer } from "microdi2";

export const { provide, singleton, alwaysFresh } = initContainer();
// DIConfig.ts:
import { singleton } from "./container.ts";
import { A } from "./A";
import type { IA } from "./IA";
import { B } from "./B";
import type { IB } from "./IB";

export const resolveA = singleton<IA>(
  // Identifier
  "IA",
  // Class
  A,
  // Dependency list
  []
);

export const resolveB = singleton<IB>(
  // Identifier
  "IB",
  // Class
  B,
  // B constructor must be invoked with an instance of IA type
  ["IA"]
);

And then, all of these classes can be received with the following:

// app.ts
import { resolve } from "./container.ts";
import { IB } from "./IB";
import { resolveB } from "./DIConfig.ts";

// approach 1 (define type manually)
const instanceB1 = resolve<IB>("IB");

// approach 2 (use exported resolver):
const instanceB1 = resolveB();

console.log(instanceB1 === instanceB2); // true

Please note the example above instantiates all the classes as singletons. If you need a class to be instantiated every time you resolve them, use alwaysFresh instead