DEV Community

Discussion on: Dependency Injection in Go using Fx

Collapse
 
pmihaylov profile image
Preslav Mihaylov

The difference is that wire uses code generation to handle DI, while Fx relies on reflection.

Both approaches have their pros and cons - code generations spits out a lot of boilerplate code which isn't so interesting, reflection makes "magic behind the scenes" making code debugging & indexing usages harder.

What I like most about Fx, however, is how it allows you to modularize your codebase - separating your code into independent modules. This is especially useful in a large codebase where there is a lot of infra going on - monitoring, tracing, logging, etc. With fx, you can encapsulate all this code & configuration into a common module which can be reused across services.

The result is that in your main function, you simply provide your module and have a lot of infra already setup out of the box.