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

@hacker-und-koch/di

v0.2.1

Published

## Basic Idea

Downloads

6

Readme

@hacker-und-koch/di

Basic Idea

Dependency injection allows to easily distribute class instances across an application runtime. It also supports comfortable mocking in unit tests and strong control for staged instantiation.

Minimum Viable Example [example]

import { Application, bootstrap } from '@hacker-und-koch/di';

@Application()
class App { }

bootstrap(App);

Hooks [example]

@Injectable()
class Worker implements 
    OnConfigure, 
    OnInit, 
    OnReady, 
    OnDestroy 
{
    async onConfigure() {}
    async onInit() {}
    onReady() {}
    async onDestroy() {}
}

Logger [example,details]

@Injectable()
class MyWorker {

    constructor(private logger: Logger) {
        this.logger.info("Hi"); 
        // 2020-01-01T10:10:45.1234 (i) MyWorker: Hi
    }
}

GetOpt [example,details]

@Injectable()
class MyWorker implements OnReady {

    constructor(private getopt: GetOpt) {}

    onReady() {
        this.getopt.option("host"); // "foo.com"
    }
}
$ yarn start --host=foo.com

Configuring GetOpt

TODO; meanwhile

More Depth [example]

@Injectable()
class InnerWorker {}

@Injectable()
class OuterWorker {
    constructor(private worker: InnerWorker) {}
}

@Application({
    declarations: [
        InnerWorker,
        OuterWorker,
    ]
})
class App {    
    constructor(private worker: OuterWorker) {}
}
bootstrap(App, {
    log: "info"
});

leads to output:

<timespamp> (i) bootstrap: Target: App
<timespamp> (i) Providers: Created new instance of Logger for Providers.
<timespamp> (i) Providers: Creating new instance of GetOpt
<timespamp> (i) Providers: Creating new instance of InnerWorker
<timespamp> (i) Providers: Creating new instance of OuterWorker
<timespamp> (i) Providers: Configuring 5 instances
<timespamp> (i) Providers: Done configuring
<timespamp> (i) Providers: Initializing 5 instances
<timespamp> (i) Providers: Initialization complete
<timespamp> (i) Providers: Announcing ready state to 5 instances
<timespamp> (i) bootstrap: Done bootstraping App.

Shared and Unique Instances [example]

Instances can not only be injected via constructor arguments, but also via the @Inject decorator. This method also allows to provide a custom instance id. Therefore you can have classes instanciated multiple times and reused on demand.

@Injectable()
class OuterWithSharedInstance {

    @Inject(Worker, 'foo')
    private worker1: Worker;

    @Inject(Worker, 'foo')
    private worker2: Worker;
}
@Injectable()
class OuterWithUniqueInstances {

    @Inject(Worker, 'foo')
    private worker1: Worker;

    @Inject(Worker, 'bar')
    private worker2: Worker;
}

Passing configs [example]


interface MyWorkerConfig {
    myOption: string;
}

@Injectable()
class MyWorker implements OnConfigure {

    @InjectConfiguration()
    private config: MyWorkerConfig;

    onConfigure() {
        console.log(`My option is: ${this.config.myOption}`);
    }
}

@Application({
    declarations: [MyWorker],
    configs: [config<MyWorkerConfig>(MyWorker, {
        myOption: 'foo',
    })]
})
class MyApp {
    constructor(worker: MyWorker) { }
}

Bootstrap Options

TODO