Getting Started

  • Get Started in 5 Minutes
    • Before You Start
    • Tutorial Overview
    • Quick Preview
  • Installation
    • Install godi
    • Verify It Works
    • Requirements
    • Framework Integrations (Optional)
  • Your First Container
    • The Pattern
    • Step 1: Create a Collection
    • Step 2: Register a Service
    • Step 3: Build the Provider
    • Step 4: Resolve the Service
    • Complete Example
    • What Just Happened?
    • Key Points
  • Adding Services
    • The Magic: Automatic Wiring
    • How It Works
    • A Realistic Example
    • Constructor Patterns
    • Interface Registration
    • Key Points
  • Using Lifetimes
    • The Three Lifetimes
    • Singleton - One Instance Forever
    • Scoped - One Instance Per Scope
    • Transient - New Instance Every Time
    • Complete Example
    • The Golden Rule
    • Quick Reference
  • HTTP Integration
    • The Pattern
    • Basic Setup
    • What’s Happening
    • Request-Scoped Data
    • Setting Request Data
    • Complete Example
    • Framework Integrations
  • Next Steps
    • Building a Web Application?
    • Organizing a Large Application?
    • Simplifying Complex Constructors?
    • Testing Your Application?
    • Something Went Wrong?
    • Quick Reference
      • Core Concepts
      • Features
      • Integrations
    • Get Help

Concepts

  • How godi Works
    • The Big Picture
    • Step by Step
      • 1. You Write Constructors
      • 2. You Register Services
      • 3. godi Builds the Graph
      • 4. You Request Services
    • Type Resolution
    • Instance Caching
    • Error Handling
    • Cleanup
  • Service Lifetimes
    • Visual Overview
    • Singleton
      • When to Use Singleton
      • Singleton Lifecycle
    • Scoped
      • When to Use Scoped
      • Scoped Lifecycle
    • Transient
      • When to Use Transient
      • Transient Lifecycle
    • The Golden Rule
      • Valid Dependencies
      • Invalid Dependencies
    • Performance Considerations
      • Memory Usage
      • Creation Cost
    • Quick Reference
    • Common Patterns
      • Web Application
      • Background Worker
  • Scopes and Isolation
    • What is a Scope?
    • Creating Scopes
    • Scope Behavior
      • Scoped Services: Same Within Scope
      • Singletons: Same Everywhere
      • Transients: Always New
    • Scopes in Web Applications
    • Context Integration
    • Scope Cleanup
    • Framework Integration
    • Advanced: Nested Scopes
    • Common Patterns
      • Request-Per-Scope
      • Database Transaction Per Request
  • Modules
    • Why Modules?
    • Creating Modules
    • Module Organization
    • Example: Infrastructure Module
    • Example: Domain Module
    • Composing Modules
    • Module Dependencies
    • Conditional Modules
    • Testing with Modules
    • Best Practices
      • 1. One Module Per Domain
      • 2. Infrastructure in Its Own Module
      • 3. Keep Modules Focused
      • 4. Document Cross-Module Dependencies

Guides

  • Building Web Applications
    • Application Structure
    • Complete Example
    • Key Patterns
      • 1. Layered Architecture
      • 2. Lifetime Assignments
      • 3. Request Context Pattern
      • 4. Middleware Integration
      • 5. Database Transaction Per Request
    • Graceful Shutdown
  • Testing with godi
    • Testing Strategies
      • 1. Unit Testing with Mocks
      • 2. Integration Testing with Test Container
      • 3. HTTP Handler Testing
    • Test Modules
    • Interface-Based Mocking
    • Testing Error Paths
    • Table-Driven Tests
    • Best Practices
  • Debugging godi Errors
    • Build-Time Errors
      • Circular Dependency Detected
      • Missing Dependency
      • Lifetime Conflict
      • Constructor Error
    • Runtime Errors
      • Service Not Found
      • Scope Disposed
      • No Scope in Context
    • Debugging Tips
      • 1. Use Resolve Instead of MustResolve
      • 2. Check Registrations
      • 3. Validate Dependencies Early
      • 4. Log Resolution for Debugging
    • Common Mistakes
      • Wrong Type in Generic Parameter
      • Forgetting to Close Scopes
      • Registering Instance Instead of Constructor
  • Migration Guide
    • From Manual Dependency Injection
      • Before
      • After
      • Benefits
    • From Uber Fx
      • Fx Concepts → godi Concepts
      • Before (Fx)
      • After (godi)
      • Lifecycle Hooks
    • From samber/do
      • do Concepts → godi Concepts
      • Before (do)
      • After (godi)
      • Adding Scopes
    • From Google Wire
      • Wire Concepts → godi Concepts
      • Before (Wire)
      • After (godi)
      • Interface Binding
    • Gradual Migration
      • Step 1: Add godi for New Code
      • Step 2: Move Services Incrementally
      • Step 3: Full Migration
    • Common Migration Issues
      • Constructor Signature Changes
      • Global Variables
      • Testing After Migration

Features

  • Keyed Services
    • The Problem
    • The Solution: Keys
    • Registration
    • Resolution
    • Use Cases
      • Multiple Database Connections
      • Strategy Pattern
      • Environment-Specific Services
    • With Parameter Objects
    • Best Practices
      • Use Constants for Keys
      • Fallback Pattern
    • Common Mistakes
      • Duplicate Keys
      • Wrong Type
  • Service Groups
    • The Problem
    • The Solution: Groups
    • Registration
    • Resolution
    • Use Cases
      • Validation Chain
      • Middleware Stack
      • Event Handlers
      • Plugin System
    • With Parameter Objects
      • Optional Groups
    • Combining Keys and Groups
    • Ordering
    • Empty Groups
  • Parameter Objects
    • The Problem
    • The Solution: Parameter Objects
    • Basic Usage
    • Field Tags
      • Optional Dependencies
      • Named Dependencies
      • Group Dependencies
      • Combining Tags
    • Benefits
      • 1. Cleaner Signatures
      • 2. Easier Refactoring
      • 3. Self-Documenting
    • Testing
      • Direct Construction
      • With Provider
    • Common Mistakes
      • Named Embedding
      • Unexported Fields
  • Result Objects
    • The Problem
    • The Solution: Result Objects
    • Basic Usage
    • Field Tags
      • Named Services
      • Group Membership
      • Interface Binding
    • Use Cases
      • Database with Health Checker
      • Cache Layer
      • HTTP Client Suite
    • Combining In and Out
    • With Errors
    • Common Mistakes
      • Named Embedding
      • Unexported Fields
  • Interface Binding
    • The Problem
    • The Solution: As Option
    • Basic Usage
    • Multiple Interfaces
    • With Keys and Groups
    • Use Cases
      • Swappable Implementations
      • Repository Pattern
      • Dependency Inversion
    • With Parameter Objects
    • Testing
    • Common Mistakes
      • Resolving Concrete When Registered as Interface
      • Forgetting As Option
  • Resource Cleanup
    • How It Works
    • The Disposable Pattern
    • Disposal by Lifetime
      • Singleton Disposal
      • Scoped Disposal
      • Transient Disposal
    • Disposal Order
    • Error Handling
    • Practical Examples
      • Database Connection
      • Database Transaction
      • File Handler
      • HTTP Client with Keep-Alive
    • Web Application Pattern
    • Manual Disposal
    • Best Practices
    • Common Resources to Dispose

Integrations

  • Gin Integration
    • Installation
    • Quick Start
    • ScopeMiddleware
      • Configuration Options
    • Handle
      • Handler Options
    • Complete Example
    • Accessing Scope Manually
    • Route Groups
    • Error Responses
  • Chi Integration
    • Installation
    • Quick Start
    • ScopeMiddleware
      • Configuration Options
    • Handle
      • Handler Options
    • Complete Example
    • Route Groups
    • Accessing URL Parameters
    • Accessing Scope Manually
    • Subrouters
  • Echo Integration
    • Installation
    • Quick Start
    • ScopeMiddleware
      • Configuration Options
    • Handle
      • Handler Options
    • Complete Example
    • Route Groups
    • Accessing URL Parameters
    • Accessing Scope Manually
    • Request Binding
    • Error Handling
  • Fiber Integration
    • Installation
    • Quick Start
    • ScopeMiddleware
      • Configuration Options
    • Handle
      • Handler Options
    • Complete Example
    • Route Groups
    • FromContext Helper
    • Accessing URL Parameters
    • Request Body Parsing
    • Important: Fiber’s Context Handling
  • net/http Integration
    • Installation
    • Quick Start
    • ScopeMiddleware
      • Configuration Options
    • Handle
      • Handler Options
    • Complete Example
    • Wrap Helper
    • Accessing URL Parameters (Go 1.22+)
    • Accessing Scope Manually
    • Middleware Chaining
    • Subrouting
    • JSON Response Helper

Reference

  • GitHub
  • API Docs
  • Changelog

Quick Links

  • GitHub
  • pkg.go.dev
  • Go Report Card

Community

  • Discussions
  • Issues
godi
  • Search


© Copyright 2026, junioryono.