Dependency Injection

Designing loosely coupled code through dependency injection, reducing testability barriers and hidden dependencies.

48 stars 10 forksSoftware Development Plugin marketplace

Install

Claude Code plugin
/plugin marketplace add sethdford/claude-skills

The repo is a Claude Code plugin marketplace. Run /plugin afterwards to pick the plugin that includes this skill.

skills CLI (Claude Code, Cursor, Codex and more)
npx skills add sethdford/claude-skills --skill dependency-injection
Manual install
git clone --depth 1 https://github.com/sethdford/claude-skills.git /tmp/claude-skills
mkdir -p ~/.claude/skills
cp -r /tmp/claude-skills/engineer/code-quality/skills/dependency-injection ~/.claude/skills/dependency-injection

Personal skills live in ~/.claude/skills. Use .claude/skills in a project folder to share a skill with your team.

From the SKILL.md

# Dependency Injection

Fundamental pattern for loose coupling and testability.

## Context

You are helping the engineer apply dependency injection. If code is provided, identify tightly coupled dependencies and suggest injection patterns. DI is not optional for testable, maintainable code.

## Domain Context

- **Loose Coupling**: Dependencies are explicit parameters, not hidden inside the class
- **Testability**: You can inject mocks, stubs, or fakes for testing without modification
- **Inversion of Control**: Class doesn't create its dependencies; they're provided
- **Three Patterns**: Constructor Injection (preferred), Setter Injection, Interface Injection
- **Container**: Optional; frameworks like Spring, Guice manage dependency graphs

## Instructions

1. **Identify Hard Dependencies**: What does the class create or reference? httpClient, database, logger?
2. **Declare Dependencies**: Add constructor parameters for each dependency (prefer constructor over setter)
3. **Make Testable**: Can you pass in a mock? If not, you're still too tightly coupled
4. **Use Interfaces**: Depend on abstractions (Logger), not concrete implementations (ConsoleLogger)
5. **Avoid Service Locator**: Don't pass in a container or factory; too implicit
6. **Document Contracts**: Make it clear which dependencies are required vs. optional
7. **Keep Constructors Simple**: Only assign fields; avoid logic or other dependencies
Read the full skill on GitHub

Details

Skill name
dependency-injection
Path
engineer/code-quality/skills/dependency-injection/SKILL.md
License
MIT
Repo updated
11 March 2026

FAQ

What does the Dependency Injection skill do?

Designing loosely coupled code through dependency injection, reducing testability barriers and hidden dependencies.

How do I install the Dependency Injection skill?

Claude Code plugin: /plugin marketplace add sethdford/claude-skills. Skills go in ~/.claude/skills (personal) or .claude/skills (project), and Claude loads them automatically when a task matches the description.

Is Dependency Injection popular?

It lives in sethdford/claude-skills, which has 48 GitHub stars and 10 forks.

Related skills

Browse the most popular Claude skills, all software development skills, or write your own with the skills generator.