Comments (7)
Maybe, it could be possible manage those dependencies through a context, for example, creating an ArticleContext interface such that
type ArticleContext interface {
GetARepo() ARepo
GetBRepo() BRepo
GetCRepo() CRepo
....
GetZRepo() ZRepo
}
Then, you just need to call inside usecase the respective repository:
func (a *articleUsecase) Fetch(c MyArticleContext, cursor string, num int64) (res []domain.Article, nextCursor string, err error) {
....
aRepo := c.GetARepo()
....
}
from go-clean-arch.
@bluntdel and @bxcodec what do you think about https://github.com/google/wire guys?
from go-clean-arch.
Wow, good question, personally I haven't do any elegant way.
Because for me personally, I'd rather see an explicit one rather than implicit, like in Java world with a lot of decorator things, that really consumes a lot of my mind budget to understand how is it worked.
Also in this explicit way, I can do knowledge transfer to junior engineers easily without the need to know how dependency injection tools work.
@frederikhors , I'll look into it, and try to understand it. If it's not making things more complicated, then it's a good to try.
from go-clean-arch.
@bluntdel surely it is a problem if we create a monolith using this this design pattern. It will create a long dependency injection call
func New(aRepo a.repository, bRepo b.repository ...) AUsecase { ... }
i have found a great library called fx to reduce the code boilerplate of the dependency injection.
@frederikhors the difference between wire and fx is that wire is a code generator and fx is runtime auto inject dependency.
from go-clean-arch.
@bxcodec
I made a sample project with dependency injection framework uber-go/fx.
Could you feedback to me?
https://github.com/mcauto/todolist-api
from go-clean-arch.
I wonder that is this way testable? and where to place ArticleContext.
from go-clean-arch.
이런 식으로 테스트 가능한지 궁금합니다. 그리고 ArticleContext를 배치할 위치.
How about this?
https://github.com/mcauto/todolist-api/blob/main/modules/domains/todo/service_test.go#L38
from go-clean-arch.
Related Issues (20)
- Error Encountered with $ make up Command Leading to MySQL Connection Panic HOT 1
- Definition of domain
- How to handle multiple Repository transactions HOT 2
- What is the entity, is it swollen in the domain? HOT 2
- How do you reference ID's HOT 2
- why you had put uc with business logic nearly infrastructure details like a sql queries? HOT 2
- Questions About Whether Necessary To Use Pointer For Usecase HOT 1
- Question About Layers
- More than one repository files? HOT 4
- Question about directory layer HOT 1
- Question about manage 3rd service HOT 2
- accept interface, return pointer struct
- How to support transaction? HOT 1
- Repository should be Unexported except by UseCase
- Cyclic Dependence
- Vulnerability of dependency "golang.org/x/net" HOT 1
- If domain struct does not equal to database's schema, what should be done regarding repository's interface? HOT 1
- Database Connection Error HOT 1
- Enhance & Feat: Database connection with go wire dependency injection
- How to organize another domain? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go-clean-arch.