Skip to content

Conversation

@hikahana
Copy link
Collaborator

@hikahana hikahana commented Jul 16, 2025

対応Issue

resolve #0

概要

Google Wireを使った依存性注入システムを導入し、従来の手動による依存性注入を自動化しました。

主な変更点

  • Google Wire v0.6.0の導入: 依存性注入の自動化ツールを導入
  • 各レイヤーでのwireファイル作成: Controller、Repository、UseCaseの各レイヤーにwireファイルを追加
  • di.goの削除: 手動DIからWireによる自動生成に移行
  • Makefileの更新: make wire-genコマンドを追加し、wire_gen.goの生成を自動化

技術的な改善

  • 依存性注入の管理が宣言的になり、メンテナンスが容易に
  • コンパイル時に依存関係の検証が行われ、実行時エラーのリスクが軽減
  • 新しいコンポーネントの追加時の定型的な作業が削減
  • 各レイヤー層ごとにwire.goを作成し、di/wire.goでそれらをすべてまとめてwire genできるようにしました。
    下記雑な図
FinanSu/
├── api/
│   ├── main.go                          # アプリケーションエントリポイント
│   ├── internals/                       # 内部層
│   │   ├── di/                          # 依存性注入 (Wire)
│   │   │   ├── wire.go                  # Wire設定ファイル
│   │   │   └── wire_gen.go              # Wire生成ファイル
│   │   │
│   │   └── usecase/                     # ユースケース層
│   │       ├── wire.go                  # UseCase Provider Set
│   │
│   ├── externals/                       # 外部層
│   │   ├── controller/                  # コントローラー層
│   │   │   ├── wire.go                  # Controller Provider Set
│   │   │
│   │   └── repository/                  # リポジトリ層
│   │       ├── wire.go                  # Repository Provider Set

画面スクリーンショット等

  • http://localhost:1323/ - アプリケーションの基本的な動作確認
    ※画面表示に変更はありません

テスト項目

  • make wire-gen コマンドでwire_gen.goが正常に生成されること
  • アプリケーションが正常に起動すること(make run
  • 既存のAPIエンドポイントが正常に動作すること(curl -s http://localhost:1323/
  • 各レイヤー間の依存性注入が正常に動作すること
  • 既存の機能に影響がないこと(CRUD操作など)

備考

  • Air によるホットリロードが設定されているため、wire_gen.go生成後は自動的にリビルドされます
  • 新しいAPI作成時にはwire設定の追加が必要になる場合があります
  • 依存性注入の設定は各レイヤーのwire.goファイルで管理されます

This comment was marked as outdated.

@hikahana hikahana requested a review from Copilot July 16, 2025 04:14
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Google Wireで依存性注入を自動化するためにリファクタリングを実施したよ✨

  • Wire v0.6.0導入で手動DIを宣言的に置き換え!やばたにえん💖
  • Controller/Repository/UseCase各層にwire.goを追加&wire_gen.goでコード生成🛠️
  • main.goやテスト、MakefileもInitializeServer呼び出しへ対応&wire-genコマンド追加🎉

Reviewed Changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
api/internals/di/wire.go Wire用injector定義を追加してInitializeServerを生成可能に
api/internals/di/wire_gen.go 手動DIのコードをWire生成コードに置き換え
api/internals/usecase/wire.go UseCase層のProviderセットを追加
api/externals/repository/wire.go Repository層のProviderセットを追加
api/externals/controller/wire.go Controller層のProviderセットを追加
api/main.go InitializeServer呼び出し&panic/CloseDB処理をWire対応に変更
api/test/sample_test.go テストコードをWire対応にリファクタリング
api/go.mod Wire導入に伴うgo.mod更新
Makefile wire-gen & go-mod-tidyコマンドを追加
Comments suppressed due to low confidence (1)

api/go.mod:77

  • このプロジェクトで github.com/google/subcommands パッケージを使用している箇所が見当たらないから、不要な依存として削除したほうがコードがすっきりするよ✂️
	github.com/google/subcommands v1.2.0 // indirect

Copy link
Collaborator

@Kubosaka Kubosaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ぱっと見良さそう
APIの作成するときの手順とかざっくりメモっとくと良さそう
README.mdでいいか

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants