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

@karcass/container

v0.1.5

Published

Simple IoC container

Downloads

107

Readme

@karcass/container

Very tiny and simple async IoC container with dependency injection support used in karcass skeleton

Installation

npm install @karcass/container

Usage

import { Container } from '@karcass/container'

class ConsoleLogger {
    public log(text: string) {
        console.log(text)
    }
}

class HelloMessagePrinter {
    public constructor(protected helloSayer: HelloSayer) {}

    public print(username: string) {
        this.helloSayer.log(`Hello, ${username}!`)
    }
}

class DummyClass {}

const container = new Container()

container.add(HelloWorldMessagePrinter, async () => {
    const logger = await container.get(ConsoleLogger)
    console.log('HelloMessagePrinter initialization...')
    return new HelloMessagePrinter(logger)
})
container.add(ConsoleLogger, () => {
    console.log('ConsoleLogger initialization...')
    return new ConsoleLogger()
}
container.add(DummyClass, () => {
    console.log('DummyClass initialization...')
    return new DummyClass()
})

container.get(HelloMessagePrinter).then(printer => printer.print('Alice'))

This example will print:

ConsoleLogger initialization...
HelloMessagePrinter initialization...
Hello, Alice!

Also you can use addInplace method for immediate initialization of some instances for some reasons:

container.add(HelloWorldMessagePrinter, () => {
    const logger = container.get(ConsoleLogger)
    console.log('HelloMessagePrinter initialization...')
    return new HelloMessagePrinter(logger)
})
container.add(ConsoleLogger, () => {
    console.log('ConsoleLogger initialization...')
    return new ConsoleLogger()
}
container.addInplace(DummyClass, () => {
    console.log('DummyClass initialization... It was first.')
})

container.get(HelloMessagePrinter).print('Alice')

Ouput:

DummyClass initialization... It was first.
ConsoleLogger initialization...
HelloMessagePrinter initialization...
Hello, Alice!

You can use dependency injection instead of service construction by hands:

import { Container, Dependency } from '@karcass/container'

class FirstClass {}

class SecondClass {
    public constructor(@Dependency(FirstClass) firstClassInstance: FirstClass) {
        console.log(`${firstClassInstance.constructor.name} loaded`)
    }
}

const container = new Container()
container.add(FirstClass)
await container.addInplace(SecondClass)

Or you can just create instance of SecondClass using inject method, which creates instance of constructor and injects corresponding dependencies. This method doesn't perform addition of created object into self (container's) index:

const secondClassInstance = await container.inject(SecondClass)

Feel free to use text keys for services:

/* ... */
public constructor(@Dependency('first-class') firstClassInstance: FirstClass) {
/* ... */
container.add('first-class', () => new FirstClass())
await container.addInplace(SecondClass)

Available methods

  • add<T>(key: costructor | string, initializer?: () => T | Promise<T>): void;
  • addInplace<T>(key: consructor | string, initializer?: () => T | Promise<T>): Promise<T>;
  • get<T>(key: constructor | string): Promise<T>;
  • getAll(): Promise<T[]>;
  • getKeys(): (string | constructor)[].