Hi Steven, thank you for the article, I have a question!
Why do you pass a repository as param when init interface?
Such as services.Food is passed as params of interfaces.NewFood initialization. foods := interfaces.NewFood(services.Food, services.User, fd, redisService.Auth, tk)
I think that pass a application is better choice! How do you think about it?
Hi bro, Sorry for the late reply. Just seeing this now. interfaces.NewFood() is a constructor, so we inject dependencies of other services. This is considered best practice, so you avoid the usage of globals in your code.
Some comments have been hidden by the post's author - find out more
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Hi Steven, thank you for the article, I have a question!
Why do you pass a repository as param when init interface?
Such as
services.Food
is passed as params ofinterfaces.NewFood
initialization.foods := interfaces.NewFood(services.Food, services.User, fd, redisService.Auth, tk)
I think that pass a application is better choice! How do you think about it?
Hi bro, Sorry for the late reply. Just seeing this now. interfaces.NewFood() is a constructor, so we inject dependencies of other services. This is considered best practice, so you avoid the usage of globals in your code.