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

slim-di

v0.0.8

Published

Minimal dependency injection framework using decorators

Readme

Slim DI

Minimalistic DI library weighing in at <1 kB. Built for usage with decorators and reflect-metadata.

Installation

npm i slim-di

Usage

slim-di uses typescript and classes to handle dependency injection. The first thing you need to do is declare your root class. By default slim-di creates a single instance of each class in the program.

import "reflect-metadata";

import { Injectable, createContainer } from 'slim-di';

@Injectable()
class FishingPole {}
@Injectable()
class FishingHook {}

@Injectable()
class FishingGear {
  constructor(
    private readonly pole: FishingPole,
    private readonly hook: FishingHook
  ) {}
}

@Injectable()
class FishingBoat {}

@Injectable()
class FisherManRoot {
  constructor(
    private readonly gear: FishingGear, 
    private readonly boat: FishingBoat
  ){}
}


async function main(){
  const container = createContainer(FisherManRoot);
  // Logs true
  console.log(container.get(FishingBoat) === container.get(FishingBoat))
}
main()

Lifecycle hooks

slim-di exposes one lifecycle hook called onInit which triggers during instantiation and can be used to connect to databases or other init-work. To trigger the hook on your class instance you must call the DIContainer.init method.

import { PrismaClient } from "@prisma/client";
import { Injectable, createContainer } from 'slim-di';

@Injectable()
export class Prisma extends PrismaClient implements OnInit {
  async onInit() {
    await this.$connect();
  }
};


async function main() {
  const container = await createContainer(Prisma).init();
  const data = await container.get(Prisma).entity.findMany();
}

Examples

Here is a small example using an express server and prisma.

import "reflect-metadata";

import { PrismaClient } from "@prisma/client";
import express from "express";
import { createContainer, Injectable } from "slim-di";
import { OnInit } from "slim-di";

@Injectable()
export class Prisma extends PrismaClient implements OnInit {
  async onInit() {
    console.log("Connecting to prisma...");
    await this.$connect();
    console.log("Connected!");
  }
}

@Injectable()
export class ExpressClient {
  public app = express();
}

@Injectable()
export class UserRouter {
  constructor(
    private readonly express: ExpressClient,
    private readonly prisma: Prisma
  ) {}

  register() {
    this.express.app.get("/users", async (_, res) => {
      const users = await this.prisma.user.findMany();
      res.json(users);
    });
  }
}

@Injectable()
export class MyApplication implements OnInit {
  constructor(
    private readonly express: ExpressClient,
    private readonly userRouter: UserRouter
  ) {}

  private port = 3000;

  onInit() {
    this.userRouter.register();
    this.express.app.listen(this.port, () => {
      console.log("Listening on port", this.port);
    });
  }
}

async function main() {
  await createContainer(MyApplication).init();
}

main();