captcha
fx
Our great sponsors
Stars - the number of stars that a project has on GitHub. Growth - month over month growth in stars.
Activity is a relative number indicating how actively a project is being developed. Recent commits have higher weight than older ones.
For example, an activity of 9.0 indicates that a project is amongst the top 10% of the most actively developed projects that we are tracking.
captcha
We haven't tracked posts mentioning captcha yet.
Tracking mentions began in Dec 2020.
fx
- How do you do dependency injection in go?
-
Thoughts on DI containers?
Also why use dig directly? I really prefer using FX who is recommended by Uber
-
Dependency injection in Go with Uber-go/fx
That's a very fair perspective, and build-time verification of your dependency graph is great. That said, fx's approach allows for a more dynamic dependency graph. (For example, fx.Replace[0].)
The documentation for Fx, along with nearly all the applications I saw internally, use the dependency injection container only in main - once the application starts successfully, there's no more interaction with the container. For Uber at the time, this struck a useful balance between safety and the difficulty of distributing yet another versioned code gen tool to thousands of repositories.
-
How do you deal with dependency injection?
You can try Fx, it works pretty well. You can opt out of a lot of features if you just want DI.
-
fx: useful functional programming helpers without using interface{}, based on Go 1.18 generics
Will advise you to change the library name as there is another popular library with same name. https://github.com/uber-go/fx
- Implementing Graceful Shutdown in Golang
-
[Question] How to split main.go into separate packages/files whilst maintaining Dependency Injection?
Try fx https://github.com/uber-go/fx. I separate my code into packages in exactly the same way that you want to do and fx takes care of the DI.
- Any workflow with dependent functions?
-
Gracefully shutting down multiple servers in a single prorgam
I really like use fx as a dependency and lifecycle manager (https://github.com/uber-go/fx) here’s an example of how it can gracefully handle multiple server startups and shutdowns (https://github.com/brandenc40/green-mountain-grill/blob/master/server/server/server.go#L37)
-
Show HN: We wrote a book about building business applications in Go
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.
What are some alternatives?
dig - A reflection based dependency injection toolkit for Go.
wire - Strict Runtime Dependency Injection for Golang
wire - Compile-time Dependency Injection for Go
container - A lightweight yet powerful IoC dependency injection container for the Go programming language
todo-api-microservice-example - Go microservice tutorial project using Domain Driven Design and Onion Architecture!
vfs for golang - Virtual filesystem library written in golang
gommit - Enforce git message commit consistency
watermill - Building event-driven applications the easy way in Go.
uuid - Generate, encode, and decode UUIDs v1 with fast or cryptographic-quality random node identifier.
stateless - Go library for creating state machines
archiver - Easily create & extract archives, and compress & decompress files of various formats
morse - Morse Code Library in Go