What does HackerNews think of fx?

A dependency injection based application framework for Go.

Language: Go

#19 in Framework
#84 in Go
#76 in Go
Personally, a larger fan of Uber FX [0].

You don't "need" it in golang, but for me, it encourages nice code separation in a way that makes it really easy to write tests for my components. You tend to think a lot more about how code is organized in order to make it as easy as possible to unit test. I also like the service start/stop functionality.

[0] https://github.com/uber-go/fx

As an old Java head, I found FX [1] to fill a missing DI gap for me. Some can argue that it isn't really needed in go, and I tend to agree, but after using it in a few large projects, I find that it encourages a good separation of concerns that enables things to be easier tested as well as prevents cyclical imports.

[1] https://github.com/uber-go/fx

Take a look at the major DI frameworks for Go, Wire [0] and FX [1]. They just plumb the gaps between methods that return types and methods that want them. Although technically they work for concrete types, 99% of the time it's going to be an interface, so that you can substitute a mock for testing.

Prior to DI frameworks we used global variables, often initialized in a package's init() method.

>The desire to do this reflects a misunderstanding of interfaces.

Generally you have a few layers: gRPC/HTTP/Kafka handler, business logic, and database or external service access. Layers are unit tested individually against mocks of the layers below. Because you're going to inject a mock, you can't depend on a concrete type, so you depend on an interface. Often when you're developing you want to know what the concrete implementation of a lower layer does, so it's useful to have "go-to-definition" see through the interface declaration to its implementations.

I think the implicit satisfaction of interfaces is very cool and I wish I had it in every language. I wouldn't give it up just to simplify the IDE's job. But the IDE having this functionality does matter.

[0] https://github.com/google/wire

[1] https://github.com/uber-go/fx

Doesn't replace context, and neither is it alone in terms of being a DI library, [1].

[1] https://github.com/uber-go/fx