Go Dependency Injection
With all the Go coding I’ve done so far except for some reason work in ShowTime! has been this pattern.
-
I have a business object like video and I want to create a CRUD interface around it.
-
I create a struct with an
er
on the end of the business object’s name i.e.videoer
. -
I add a db dependency to it and create a constructor function.
-
Then I make all functions on the business object use ID’s in any function that involves retrieval.
This pattern is great for getting running though. But I feel it lacks depth.
I don’t think this pattern is good for a couple of reasons.
- The throwing about of IDs everywhere as just int types feels unsafe as variables can be easy to muddle up.
What I’m trying to do now
This is still new to me so still getting my bearings. But effectively taking the dependency injection a step further.