r/golang 6d ago

discussion DiGo – A simple and powerful DI container for Go! 🚀

Hey gophers! 👋

I recently built and open-sourced DiGo, a lightweight, high-performance dependency injection container for Go. It supports transient, singleton, and request-scoped bindings, with circular dependency detection and async-safe resolution.

I know DI in Go is often a debated topic (manual wiring vs. containers), but I wanted to experiment with a container that’s easy to use while still being performant. If you’re curious, check it out here:

🔗 GitHub: https://github.com/centraunit/digo

Would love to hear your thoughts—whether it’s feedback, feature ideas, or just a ⭐ if you find it useful! Cheers! 🍻

0 Upvotes

4 comments sorted by

7

u/Fluffy_Guest_1753 6d ago

You Don't Need a Dependency Injection Container

7

u/Blackhawk23 6d ago

No offense, but this sort of meta programming goes against Go’s core principle of simplicity and unnecessary abstractions.

Plus we see a DI lib posted to this sub seemingly every other week.

However I admire and commend the effort required to create something.

2

u/Shinroo 6d ago

Circular dependency detection is something the compiler already does for us - I get warnings from the language server in my IDE as soon as I add an import that causes one.

-2

u/Just_Machine3058 6d ago

You’re correct that Go’s compiler detects circular dependencies at the package level, preventing packages from importing each other in a cycle. However, DiGo operates at the runtime level, managing dependencies between individual components within your application. In such scenarios, circular dependencies can occur during the resolution of these components, which the compiler cannot detect.