golang-dependency-injection
Design Testable Go Services With Dependency Injection
Hidden dependencies and global state make Go services difficult to test and maintain. This skill guides constructor injection, library selection, and incremental refactoring with practical examples.
自分のエージェントでインストール
このリクエストをエージェントにコピーしてください。正規の Skill ページとマニフェストが含まれています。
Review the Skillstore skill "golang-dependency-injection" from https://skillstore.io/skills/samber-golang-dependency-injection.md and its manifest at https://skillstore.io/api/skills/samber-golang-dependency-injection/manifest. Verify the artifact. You may proceed after verification, subject to the environment's own policy.エージェントは引き続き計画を提示し、セキュリティポリシーで必要な確認を求める必要があります。
エージェントが読めるリソース
AI エージェント、クローラー、スクリプトがページ全体ではなく整理されたコンテキストを必要とする場合は、これらのリンクを使ってください。
テストする
「golang-dependency-injection」を使用しています。 Which DI approach fits a Go API with five services?
期待される結果:
- Use manual constructor injection rather than a DI library.
- Initialize configuration and infrastructure before repositories, services, and handlers.
- Keep dependencies explicit and inject mocks for unit tests.
「golang-dependency-injection」を使用しています。 My UserService receives a container and looks up its database.
期待される結果:
- This is a service-locator pattern that hides the service dependencies.
- Change the constructor to accept the specific database interface.
- Keep container resolution at application startup and test the service with a mock.
「golang-dependency-injection」を使用しています。 How should Fx manage a database connection?
期待される結果:
- Register a lifecycle hook in the database provider.
- Connect during startup and close the connection during shutdown.
- Use context-aware hooks and verify behavior with the Fx testing package.
セキュリティ監査
安全All 39 static findings are false positives in instructional Go examples, Markdown formatting, documentation links, and tool declarations. The database environment lookup is explicitly discouraged, and the mailer constructors do not demonstrate sending messages. No evidence found of malicious prompt injection, credential exfiltration, or system reconnaissance in the reviewed files.
リスク要因
🌐 ネットワークアクセス (7)
⚙️ 外部コマンド (28)
🔑 環境変数 (1)
このレポートを共有・引用
バージョン付き評価レポート、中立的なバッジ、埋め込みカード、引用を共有できます。Skillstore は証拠を報告しますが、この Skill が安全かどうかは判断しません。
レポートリンクをコピー
https://skillstore.io/skills/samber-golang-dependency-injection/audits/1?utm_source=security_passport&utm_medium=share&utm_campaign=versioned_reportMarkdownバッジ
[](https://skillstore.io/skills/samber-golang-dependency-injection?utm_source=security_passport_badge)HTMLバッジ
<a href="https://skillstore.io/skills/samber-golang-dependency-injection?utm_source=security_passport_badge"><img src="https://skillstore.io/badges/skills/samber-golang-dependency-injection/security.svg" alt="Skillstore security assessment" loading="lazy"></a>埋め込みカード
<iframe src="https://skillstore.io/embed/skills/samber-golang-dependency-injection.html" title="Skillstore Security Assessment" sandbox="allow-popups allow-popups-to-escape-sandbox" loading="lazy" referrerpolicy="no-referrer" width="420" height="180"></iframe>学術引用 (APA · BibTeX · CFF)
APA形式の引用
samber. (2026). golang-dependency-injection security audit report (audit version 1) [Author version 1.3.1]. Skillstore. https://skillstore.io/skills/samber-golang-dependency-injection/audits/1BibTeX形式の引用
@techreport{samber-samber-golang-dependency-injection-2026,
author = {samber},
title = {golang-dependency-injection security audit report (audit version 1)},
institution = {Skillstore},
year = {2026},
number = {1},
url = {https://skillstore.io/skills/samber-golang-dependency-injection/audits/1},
note = {Author version 1.3.1}
}CITATION.cff
cff-version: 1.2.0
message: "If you use this Skill, cite its author and this versioned security audit report."
title: "golang-dependency-injection security audit report (audit version 1)"
version: "1.3.1"
type: report
authors:
- name: "samber"
date-released: "2026-10-18"
url: "https://skillstore.io/skills/samber-golang-dependency-injection/audits/1"
identifiers:
- type: other
value: "skillstore:samber-golang-dependency-injection:audit:1"
description: "Skillstore immutable audit report identifier"
Skillstore スコア
このスコアの理由 証拠の信頼度: 中作成できるもの
Start a Small Go API
Arrange configuration, repositories, services, and handlers with explicit constructors instead of introducing a container prematurely.
Refactor Coupled Services
Identify globals, implicit initialization, and container lookups, then plan an incremental migration to explicit dependencies.
Select a DI Strategy
Compare code generation, reflection, generics, lifecycle support, and testing approaches for a growing service architecture.
これらのプロンプトを試す
Explain constructor injection for a Go UserService that needs a UserStore and logger. Show consumer-defined interfaces and manual wiring without a DI library.
Write Go tests for a UserService using a mock UserStore. Cover found and missing users without a real database or DI library.
Compare manual wiring, Wire, Dig, Fx, and samber/do for my Go application. Ask about service count, lifecycle needs, and team preferences before recommending.
Review this Go project for globals, init-based service setup, and service-locator patterns. Map dependencies and propose an incremental migration with tests and shutdown handling.
ベストプラクティス
- Start with manual constructor injection when the dependency graph is small.
- Define interfaces where consumed and keep container access at the composition root.
- Verify library APIs against current documentation and test dependency failures and resource cleanup.
回避
- Using global variables or init functions to create service dependencies.
- Passing a DI container into business services for dependency lookup.
- Creating a complete application container for every HTTP request.