fx
wild-workouts-go-ddd-example
Our great sponsors
fx | wild-workouts-go-ddd-example | |
---|---|---|
13 | 11 | |
2,773 | 2,383 | |
5.4% | 5.6% | |
8.2 | 4.4 | |
12 days ago | about 1 month ago | |
Go | Go | |
MIT License | MIT License |
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.
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.
wild-workouts-go-ddd-example
- Software architecture in golang,
-
Auto-Generated C4 Architecture Diagrams in Go
Hey HackerNews!
One o the most common problems in IT projects is the problem of out-of-date documentation or lack of documentation. Architecture diagrams are an essential part of it.
C4 Model is trying to help with that by providing a tool that helps to standardize a way to create clear architecture diagrams on multiple levels.
But having a standard practice to follow is not enough to have this documentation up-to-date. Because of that, Krzysztof from my team created a script that can make these diagrams directly from the code.
Unfortunetly we can't share our company code. Fortunately, we have Wild Workouts DDD example that is a perfect use case to show the power of that tool: https://github.com/ThreeDotsLabs/wild-workouts-go-ddd-exampl....
The linked article describes all the needed steps to create these diagrams. Feel free to play with it and try to add it to your project.
If you want to know more about Wild Workouts DDD example, they are already 14 articles that describe the project in detail: https://threedots.tech/series/modern-business-software-in-go....
-
Looking for production-grade web app examples
For production grade web apps look at the following repos - https://github.com/hashicorp - https://github.com/ory/kratos - https://github.com/ThreeDotsLabs/wild-workouts-go-ddd-example
-
Project references for REST APIs
This blog talk a lot about clean architecture. Also they have an example project where they show how to create a proyect using Domain-driven design.
-
Introducing go-api-basic - another template/boilerplate RESTful web server
I personally have no issues with nesting, as long as the packages don't mix implementation details with the business rules - that's one thing I'd be careful with. If you'd like to compare the approach, here's another example (I'm one of the authors).
-
Architecture review
Here's an example of a domain model using this approach.
-
Do you do CI/CD with your Golang project?
Here an example definition for the use cases I mentioned: https://github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/blob/master/cloudbuild.yaml
-
Clean microservice example
It’s a bit more advanced than pure http and sql, but anyway: https://github.com/ThreeDotsLabs/wild-workouts-go-ddd-example
-
Avoid import cycle while following DDD
Domain type
-
Show HN: We wrote a book about building business applications in Go
Here is example code and blog series for a step-by-step DDD-based refactoring of an existing app. Don't know if they are the same as what's used in the book, but found them quite interesting.
https://github.com/ThreeDotsLabs/wild-workouts-go-ddd-exampl...
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
clean-architecture-golang - This is my purpose of how to structure a web application in golang following the clean architecture principles
captcha - :sunglasses:Package captcha provides an easy to use, unopinionated API for captcha generation
todo-api-microservice-example - Go microservice tutorial project using Domain Driven Design and Onion Architecture!
watermill - Building event-driven applications the easy way in Go.
archiver - Easily create & extract archives, and compress & decompress files of various formats
deckmaster - An application to control your Elgato Stream Deck on Linux