dependency-injection
Wire dependencies using constructor-based dependency injection throughout services, repositories, and handlers.
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-04
- Stars
- ★ 41
- Forks
- 0
01 前言 Front Matter
- name
- dependency-injection
- description
- Wire dependencies using constructor-based dependency injection throughout services, repositories, and handlers.
02 资源文件 1
- 脚本examples/di_todo_example.go1.1 KB
03 SKILL.md 正文
Dependency Injection & Construction
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
04 同仓库更多 Skills
typst
Typst document creation and package development. Use when: (1) Working with .typ files, (2) User mentions typst, typst.toml, or typst-cli, (3) Creating or using Typst packages, (4) Developing document templates, (5) Converting Markdown/LaTeX to Typst
shadcn
Manages shadcn components and projects — adding, searching, fixing, debugging, styling, and composing UI. Provides project context, component docs, and usage examples. Applies when working with shadcn/ui, component registries, presets, --preset codes, or any project with a components.json file. Also triggers for "shadcn init", "create an app with --preset", or "switch to --preset".
handoff
Compact the current conversation into a handoff document for another agent to pick up.
grilling
Grill the user relentlessly about a plan, decision, or idea. Use when the user wants to stress-test their thinking, or uses any 'grill' trigger phrases.
grill-me
A relentless interview to sharpen a plan or design.
dont-waffle
Use this skill when answering questions, explaining concepts, writing technical responses, reviewing code, or helping with development tasks. Communicate in clear, simple, standard English. Keep answers concise and focused, remove unnecessary filler and repetition, explain technical ideas in plain language, and structure information so it is easy to read and understand. When showing code, present it clearly with enough context for the developer to understand what it does and where it belongs.