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

@bonbons/di

v2.0.0-beta.3

Published

依赖注入node.js实现

Readme

Bonbons-DI

@bonbons/di

Build Status Coverage Status package version

依赖注入 node.js 实现

安装

npm install @bonbons/di --save
yarn add @bonbons/di

接入指南

import { DIContainer, InjectScope } from "@bonbons/di";
import { AbstractClass as Interface, ImplementClass as Implement } from "your/code";

// 创建di容器
const di = new DIContainer();

// 注入一个全局单例
di.register({ token: Interface, imp: Implement, scope: InjectScope.Singleton });

// 注入一个范围单例
di.register({ token: Interface, imp: Implement, scope: InjectScope.Scoped });

// 注入一个总是新建的实例
di.register({ token: Interface, imp: Implement, scope: InjectScope.New });

// 工厂方法来进行设置(最底层)
di.register({ token: Interface, imp: (scopeId?, {...}) => new Implement(...), scope: InjectScope.Singleton });

// 依赖注入工厂方法来进行设置
di.register({
  token: Interface,
  depts: [Class1, Class2],
  imp: (...args: [Class1, Class2]) => new Implement(...args),
  scope: InjectScope.Singleton
});

// 直接使用创建好的实例来解析
di.register({ token: Interface, imp: new Implement(...), scope: InjectScope.New });

// 完成解析构建
di.complete();

// 获取实例
const imp = di.get(Interface);

// 创建一个scope
di.createScope("scope_id", {...});

// 在某一个范围内获得实例
const scope_imp = di.get(Interface, "scope_id");

// 释放当前范围
di.dispose("scope_id");