dependency-injection

dependency-injection is a skill for Claude Code, Codex from cass-2003/local-workflow-skill. It costs 162 tokens per session (3,252 once invoked), scanned A, original, MIT.

A way to give a component the services it needs instead of having the component create them itself. For example, a service can receive a database connection and logger when it is constructed.

In plain words
What is it for?
Use it to structure modular applications, improve testability, choose between manual setup and a dependency-injection framework, or investigate circular dependencies.
Why use it?
It makes dependencies visible, easier to replace, and easier to fake in tests. It also avoids tightly coupling business code to one database, cache, or framework.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to structure modular applications, improve testability, choose between manual setup and a dependency-injection framework, or investigate circular dependencies.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/cass-2003/local-workflow-skill/dependency-injection
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Any agent
npx skills add cass-2003/local-workflow-skill --skill dependency-injection
Clone the repo
git clone --depth 1 https://github.com/cass-2003/local-workflow-skill

Made for: Claude Code, Codex.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for dependency-injection

README.md
[![agentmods](https://agentmods.dev/badge/skills/cass-2003/local-workflow-skill/dependency-injection/github.svg)](https://agentmods.dev/skills/cass-2003/local-workflow-skill/dependency-injection)
Your own site
<a href="https://agentmods.dev/skills/cass-2003/local-workflow-skill/dependency-injection"><img src="https://agentmods.dev/badge/skills/cass-2003/local-workflow-skill/dependency-injection/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for dependency-injection

Your own site · 80×15
<a href="https://agentmods.dev/skills/cass-2003/local-workflow-skill/dependency-injection"><img src="https://agentmods.dev/badge/skills/cass-2003/local-workflow-skill/dependency-injection.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 162 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,252 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00162 $0.03252
Opus 5 $0.00081 $0.01626
Sonnet 5 $0.00032 $0.00650
Haiku 4.5 $0.00016 $0.00325

Measured 7d ago against content hash 4fe8b0863831, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-10, from the pricing page.

Security

Grade A, and why

dependency-injection scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 7d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

skills/engineering-core/ours/dependency-injection/SKILL.md · 458 lines

How it starts

The opening of the file, as written. The whole thing — 458 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Dependency Injection Skill — DI 模式

何时使用

  • 设计模块化应用(让组件可测试 / 可替换)
  • 选择手动 DI 还是用框架(NestJS / Spring / Inversify)
  • 调试循环依赖
  • 区分 singleton / scoped / transient 生命周期
  • 评审 PR 中"new XXX()"是否合适

一、核心思想

依赖注入进来,不是依赖主动获取

// ❌ 主动依赖(hard-coded)
class UserService {
  private db = new PostgresClient()                  // 改实现要改这
  private logger = console                            // 测试无法 mock
  getUser(id: string) { return this.db.query(...) }
}

// ✅ 依赖注入(构造器)
class UserService {
  constructor(private db: Database, private logger: Logger) {}
  getUser(id: string) {
    this.logger.info({ id }, 'fetching user')
    return this.db.query(...)
  }
}

// 调用方决定具体实现
const svc = new UserService(new PostgresClient(), pino())

收益

  1. 可测试:注入 fake / mock
  2. 可替换:切 SQLite / Mock DB / Redis
  3. 显式依赖:构造器签名是合同
  4. 解耦:组件不知道依赖如何创建

二、何时用 DI 框架

多数小项目不需要框架。手动 DI 在 composition root(main / 启动文件)一处装配就够:

// composition-root.ts
export function buildApp() {
  const db = new PostgresClient(env.DATABASE_URL)
  const logger = pino({ level: env.LOG_LEVEL })
  const cache = new RedisClient(env.REDIS_URL)
  const userRepo = new UserRepo(db)
  const userSvc = new UserService(userRepo, cache, logger)
  const authSvc = new AuthService(userRepo, logger, env.JWT_SECRET)
  // ...
  return { userSvc, authSvc }
}

只在以下情况上框架

  • 大量服务(> 30 个)相互依赖,手装配维护痛
  • 需要按请求 scope 注入(NestJS / Spring Web)
  • 团队习惯 / 框架要求(Spring Boot / NestJS / Angular)

三、四种注入方式

1. Constructor Injection(首选

class Service {
  constructor(private db: Database) {}
}

依赖立即可见 / 不可变 / 强制必填。

2. Setter Injection(次选)

class Service {
  private db?: Database
  setDb(db: Database) { this.db = db }
}

适合可选依赖。但用前必须检查 null。

3. Property Injection(框架专用)

// NestJS
class Service {
  @Inject('DB') private db: Database
}

// Spring
@Autowired private Database db;

简洁但隐藏依赖(看不出有哪些)。

4. Method Injection(罕见)

Read the full file on GitHub · 458 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 7d ago First seen · 458 lines · 162 tokens per session scan A 4fe8b0863831

Subscribe to this mod's changes

dependency-injection is a skill published in the GitHub repository cass-2003/local-workflow-skill (12 stars, last pushed 2mo ago), licensed MIT. It adds 162 tokens to every session and 3,252 once invoked, about $0.0008 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.

Related

Other skills, from other repositories

server-side-calls

Call tRPC procedures directly from server code using t.createCallerFactory() and router.createCaller(context) for integration testing, internal server logic, and custom API endpoints. Catch TRPCError and extract HTTP status with getHTTPStatusCodeFromError(). Error handling via onError option.

trpc/trpc · 61 tokens

mem0-test-integration

Verify a Mem0 integration produced by /mem0-integrate. Runs in the same workspace on the same branch (loose coupling) — installs dependencies, runs the repo's native test suite, then exercises a real end-to-end smoke flow against the user's API key. Produces a scorecard. TRIGGER when: user has just run /mem0-integrate…

mem0ai/mem0 · 207 tokens

prowler-test-api

Testing patterns for Prowler API: JSON:API, Celery tasks, RLS isolation, RBAC. Trigger: When writing tests for api/ (JSON:API requests/assertions, cross-tenant isolation, RBAC, Celery tasks, viewsets/serializers).

prowler-cloud/prowler · 62 tokens

python-sdk

Implement or modify Python SDK behavior under python/composio, including tools, toolkits, sessions, auth configs, connected accounts, client integration, and shared Python models. Use for Python core runtime/API work; pair with python-testing and cross-sdk-parity when TypeScript must match.

ComposioHQ/composio · 60 tokens

convex-test

Generate convex-test tests for the app's Convex functions.

openclaw/clawhub · 16 tokens

voiden

Create and edit Voiden .void files for API testing. Covers the .void file format and all enabled extension block types.

VoidenHQ/voiden · 28 tokens