Skip to main content

Go IoC

Bring "@Autowired" to Go! Compile-time dependency injection with Spring-like syntax.

See Go IoC in Action

Familiar Spring-style syntax meets Go's compile-time safety

service/user.go
// Define your service interface
type UserService interface {
CreateUser(name string) (*User, error)
GetUser(id string) (*User, error)
}

🏷️ Familiar Annotations

Spring-like @Component, @Autowired, and @Qualifier syntax

⚡ Zero Runtime Cost

Pure compile-time code generation with no reflection or runtime overhead

🔒 Type Safe

All dependencies validated at compile time with full Go type safety

⚠️ Important: Go Anti-Patterns & Migration Strategy

This library intentionally violates Go idioms to provide a familiar migration bridge for Java/Spring teams transitioning to Go. While technically functional, it introduces anti-patterns like magic struct tags and global state containers.

Use Case: Temporary productivity bridge for Java developers learning Go. The compile-time approach ensures clean migration to idiomatic Go patterns when ready.

📖 Read Full Migration Strategy →

🍃

Spring-like Syntax

Familiar @Autowired and @Component syntax for Java developers. Use struct tags and markers for clean, Spring-style dependency injection in Go.

Compile-time Safety

Zero runtime overhead with pure code generation. All dependencies are resolved at compile time, ensuring type safety and optimal performance.

🔍

Advanced Analysis

Built-in dependency graph visualization, circular dependency detection, and comprehensive component analysis tools for better architecture insights.

Get Started in Minutes

Install Go IoC and start using dependency injection in your Go projects

1. Install the CLI

go install github.com/tuhuynh27/go-ioc/cmd/iocgen@latest
2

Add Components

Mark your structs with IoC annotations using struct tags

3

Generate Code

Run iocgen to generate type-safe wire code

4

Use Container

Initialize and use your dependency-injected services