@half0wl/container

中文文档
1.0.6发布于 2026/03/18MITTypeScriptESM + CJS零依赖近 30 天下载 6341

TypeScript 服务的轻量级装潢依赖性注射容器

中文使用文档
文档目录3 节
  1. 文档
  2. 发展
  3. 许可证

集装箱

github npm docs ci

TypeScript 的轻量级装潢依赖性注射容器.

pnpm i @half0wl/container
import { Container, BaseService, Service, Inject } from "@half0wl/container";

interface ContainerDeps {
  db: DatabaseClient;
  logger: Logger;
}

@Service()
class UserService extends BaseService<ContainerDeps> {
  findById(id: string) {
    return this.deps.db.users.findUnique({ where: { id } });
  }
}

@Service()
class AuthService extends BaseService<ContainerDeps> {
  @Inject(() => UserService)
  declare readonly userService: UserService;

  authenticate(token: string) {
    return this.userService.findById(tokenToId(token));
  }
}

const container = Container.create<ContainerDeps>({ db, logger });
const auth = container.get(AuthService);

要求数 "experimentalDecorators": true 在tsconfig.json(英语:tsconfig.

文档

完整指南和 API 参考 集装箱.lib.ray.cat。 。 。 .

发展

# install dependencies
pnpm install

# build all packages
pnpm -r build

# run tests
pnpm -r test

# lint with biome
pnpm lint

# lint and auto-fix
pnpm lint:fix

# run documentation site locally
pnpm --filter docs dev

# build documentation for production
pnpm --filter docs build

# run the demo
pnpm --filter demo build && pnpm --filter demo start

许可证

麻省理工学院

版本与发布记录

@half0wl/container 共发布 7 个版本,首次发布于 2026/03/16;过去 12 个月发布了 7 个版本。

版本发布日期距今
1.0.6latest2026/03/188 个月前
1.0.52026/03/168 个月前
1.0.42026/03/168 个月前
1.0.32026/03/168 个月前
1.0.22026/03/168 个月前
1.0.12026/03/168 个月前

关于 @half0wl/container 的常见问题

@half0wl/container 是什么?

TypeScript 服务的轻量级装潢依赖性注射容器

如何安装 @half0wl/container?

在项目目录运行 npm install @half0wl/container,或使用 pnpm add / yarn add / bun add。

@half0wl/container 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@half0wl/container 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@half0wl/container 可以商用吗?

@half0wl/container 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@half0wl/container 的下载量有多少?

根据 npm 官方下载统计,@half0wl/container 在 2026/10/17 – 2026/11/15 这 30 天内被下载 6,341 次,日均约 211 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@half0wl/container 还在维护吗?

最新版本 1.0.6 发布于 2026/03/18(8 个月前);至今共发布 7 个版本,其中过去 12 个月发布了 7 个;首次发布于 2026/03/16。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。