-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to manage dependency will be more elegant? #35
Comments
@bluntdel and @bxcodec what do you think about https://github.com/google/wire guys? |
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. |
@bluntdel surely it is a problem if we create a monolith using this this design pattern. It will create a long dependency injection call |
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()
....
} |
@bxcodec |
I wonder that is this way testable? and where to place ArticleContext. |
How about this? https://github.com/mcauto/todolist-api/blob/main/modules/domains/todo/service_test.go#L38 |
I see these codes in the main.go.
I think if articleUcase need articleRepo,articleAuthorRepo and more other repository... Dependency management will be terrible, it will produce many codes like "newAriticleUseaCase(ARepo,BRepo,CRepo...)".So if it can be more elegant? I don't think write in the main.go is a good idea.
The text was updated successfully, but these errors were encountered: