跳到正文
cccskills
免费在 GitHub 公开

dependency-injection

Wire dependencies using constructor-based dependency injection throughout services, repositories, and handlers.

中文简介正在准备中。当前显示原文说明。

Authula/authula星标 273(GitHub 273 + cccskills 0)

实测评分 未实测

查看安装方法

包含的文件(2)

  • SKILL.md2.1 KB
  • examples/di_todo_example.go1.1 KB

SKILL.md(原文)

安装前可以查看交给 AI 代理的指令内容。

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

  1. Constructor-based: Dependencies passed via function parameters
  2. Explicit over implicit: Dependencies visible in constructor signatures
  3. Interface-based: Depend on interfaces, not concrete implementations
  4. Single responsibility: Each constructor handles one entity's wiring
  5. 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

  1. Circular dependencies (Service A ??? Service B ??? Service A)
  2. Lazy initialization instead of bootstrap-time
  3. Depending on concrete types instead of interfaces
  4. Creating service instances multiple times
  5. Service retrieval without type assertion
  6. Not checking ok flag on type assertion

References

评价

还没有评价。欢迎分享你的使用感受。

评论

无需登录即可发表。欢迎分享使用感受、提问,或说明在哪些环境下无法运行。

还没有评论。来写第一条吧。

提交后会立即公开。请勿填写邮箱、电话等个人信息。URL 最多 2 个。

0 / 1000 字

此表单受 reCAPTCHA 保护,适用 Google 的隐私权政策和服务条款。

同一仓库的技能

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.

中文简介正在准备中。当前显示原文说明。

Authula/authula2732026年10月24日 更新

grill-me

免费

A relentless interview to sharpen a plan or design.

中文简介正在准备中。当前显示原文说明。

Authula/authula2732026年10月24日 更新

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.

中文简介正在准备中。当前显示原文说明。

Authula/authula2732026年10月24日 更新

Implement HTTP handlers that parse requests, invoke use cases, and format responses following REST conventions.

中文简介正在准备中。当前显示原文说明。

Authula/authula2732026年10月24日 更新

handoff

免费

Compact the current conversation into a handoff document for another agent to pick up.

中文简介正在准备中。当前显示原文说明。

Authula/authula2732026年10月24日 更新

Build pluggable authentication features using the plugin system with initialization, migrations, routes, and service registration.

中文简介正在准备中。当前显示原文说明。

Authula/authula2732026年10月24日 更新

查看 Authula 的全部技能

报告此技能的问题