# @half0wl/container 中文文档

规范地址：https://npmcn.com/package/%40half0wl/container/

版本：1\.0\.6
npm 元数据更新时间：2026-03-17T17:12:28.835Z
中文译文更新时间：2026-11-17T06:40:03.736Z
软件包许可：MIT

本文由上游 README 翻译，可能存在偏差，请结合原文核对 API、命令与配置。版权与许可归原作者所有。

原始 npm 页面：https://www.npmjs.com/package/%40half0wl/container
原文对照：https://npmcn.com/package/%40half0wl/container/?lang=original

## 关键信息（来自 npm 元数据）

- 包体积（解压后）：83 kB，9 个文件
- 模块格式：ESM + CJS
- TypeScript 类型：包内自带
- 运行依赖：0 个
- 首次发布：2026-03-16T13:38:22.582Z
- 最新版本发布：2026-03-17T17:12:28.713Z
- 近 30 天下载量：6341（2026-10-17 至 2026-11-15，npm 官方下载统计）
- 已发布版本数：7（近 12 个月 7 个）

## 中文简介

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

## 安装

```sh
npm install @half0wl/container
```

也可以使用：`pnpm add @half0wl/container`、`yarn add @half0wl/container`、`bun add @half0wl/container`

## README

# 集装箱

[![github](https://img.shields.io/github/stars/half0wl/container?logo=github)](https://github.com/half0wl/container) [![npm](https://img.shields.io/npm/v/@half0wl/container?logo=npm)](https://www.npmjs.com/package/@half0wl/container) [![docs](https://img.shields.io/badge/%F0%9F%93%9A_docs-container.lib.ray.cat-blue)](https://container.lib.ray.cat/) [![ci](https://github.com/half0wl/container/actions/workflows/ci.yml/badge.svg)](https://github.com/half0wl/container/actions/workflows/ci.yml)

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

```bash
pnpm i @half0wl/container
```

```ts
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](https://container.lib.ray.cat/)**。 。 。 .

-   [开始](https://container.lib.ray.cat/guide/getting-started)
-   [服务](https://container.lib.ray.cat/guide/services)
-   [依赖性注射](https://container.lib.ray.cat/guide/injection)
-   [追踪](https://container.lib.ray.cat/guide/tracing)
-   [测试](https://container.lib.ray.cat/guide/testing)
-   [API 参考](https://container.lib.ray.cat/api/)

## 发展

```bash
# 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
```

## 许可证

[麻省理工学院](https://npmcn.com/package/%40half0wl/container/LICENSE)

## 常见问题

### @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 和提交记录判断。

