dependency-injection

Enforce explicit constructor-based dependencies to prevent hidden coupling in service classes.

Updated Jan 25, 2026
One-click install
npx skills add https://github.com/gestrich/python-architecture --skill dependency-injection
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: dependency-injection
Source: https://github.com/gestrich/python-architecture/tree/main/plugin/skills/dependency-injection
Command: npx skills add https://github.com/gestrich/python-architecture --skill dependency-injection

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Dependency injection reduces hidden coupling by requiring explicit dependencies at construction and ensuring a clear configuration flow from entry points to services.

Core Features & Use Cases

  • Explicit constructor-based dependencies to avoid hidden defaults.
  • Fail-fast configuration: invalid/missing dependencies raise immediately.
  • Clear separation of concerns between wiring/initialization and business logic.
  • Testability: easy to supply mocks for unit tests.

Quick Start

Create a service with required collaborators and wire them in the application entry point. For example, instantiate Repository and MetadataService and pass them to the service constructor in the composition root.

Frequently Asked Questions about dependency-injection

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent hidden coupling in Python service classes?

Prevent hidden coupling in Python services by enforcing explicit constructor-based dependencies. This requires providing all collaborators as parameters during instantiation, avoiding hidden defaults or direct environment variable access inside the service logic.

What is the best way to structure dependency injection for unit testing in Python?

Structuring dependency injection for unit testing involves passing required collaborators via the constructor at the composition root. This clear separation of concerns allows you to easily supply mocks and verify business logic independently.

How does constructor-based dependency injection improve software architecture?

Constructor-based dependency injection improves software architecture by enforcing a clear top-down configuration flow from entry points to implementations. It establishes a distinct boundary between initialization wiring and business logic, ensuring fail-fast behavior for missing dependencies.

Why should services avoid reading environment variables directly for configuration?

Services should avoid reading environment variables directly to prevent hidden coupling and maintain testability. Explicit constructor parameters require configuration at the application entry point, ensuring services remain pure and fail-fast when collaborators are missing.

Can I use this dependency injection pattern with existing Python codebases?

You can apply this pattern to existing Python codebases by refactoring services to accept required collaborators as explicit constructor parameters. Moving configuration to the composition root establishes clear top-down wiring without hidden defaults.