sqlite package: package scoped db variable instead of injection #18
-
Hello Ben, first of all, thanks for the great stuff! I'm a newbie to Golang (Spring Boot switcher), and I saw many examples including real production applications when
Tell me please why use dependency injection instead of such kind of private package variable? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hi Eugene, The downside to using a global |
Beta Was this translation helpful? Give feedback.
Hi Eugene,
The downside to using a global
db
variable in your package is that it can make testing problematic. Especially if you want to parallelize tests to speed them up. I generally try to avoid global variables because it makes it more difficult to change code and reuse code over time.