Dependency Injection & Construction
SkillDev toolsWire dependencies using constructor-based dependency injection throughout services, repositories, and handlers.
Available today. Use it from your connected AI after setup.
No other account needed.
Connect ahel once, and every AI you use reads what you have installed.
Then ask your AI: use the Dependency Injection & Construction skill
What this skill tells your AI
The instructions your AI receives, as published by cliqrelay/cliqrelay in .agents/skills/backend/dependency-injection/SKILL.md and read by ahel’s review.
When to use this skill
- Wire services, repositories, and handlers with their dependencies
- Initialize core services during application bootstrap
- Pass dependencies to plugins during initialization
- Create dependency graphs that are testable and mockable
- Avoid service locators and global state
Key principles
- Constructor-based: Dependencies passed via function parameters
- Explicit over implicit: Dependencies visible in constructor signatures
- Interface-based: Depend on interfaces, not concrete implementations
- Single responsibility: Each constructor handles one entity's wiring
- Bootstrap concentrated: Wiring happens in bootstrap.go and plugin Init
Pattern
Dependency injection flow:
- Repositories accept bun.IDB and return interface
- Services accept repositories and return interface
- Use cases accept services and return struct
- Handlers accept use cases and return struct
- Plugins accept PluginContext, retrieve services, create dependencies
- No global state or service locators
Example
See examples/di_todo_example.go for:
- BuildTodosPlugin demonstrating complete DI chain
- Bottom-up wiring (Database ??? Repository ??? Service ??? UseCase ??? Handler)
- Dependency graph diagram
- Unidirectional dependency flow
Common mistakes
- Circular dependencies (Service A ??? Service B ??? Service A)
- Lazy initialization instead of bootstrap-time
- Depending on concrete types instead of interfaces
- Creating service instances multiple times
- Service retrieval without type assertion
- Not checking ok flag on type assertion
References
- bootstrap.go - Main DI entry point
- models/services.go - Service ID constants
- internal/api.go - Use case wiring
- internal/plugins/service_registry.go - Service registry implementation
Signals
- GitHub stars
- 40
- Forks
- 1
- Last commit
- Sep 2026
Advanced
- Catalog kind
- skill
- Gateway key
dependency-injection- Source
- github.com/cliqrelay/cliqrelay