Rhys' website

Go Dependency Injection

With all the Go coding I’ve done so far except for some reason work in ShowTime! has been this pattern.

  1. I have a business object like video and I want to create a CRUD interface around it.

  2. I create a struct with an er on the end of the business object’s name i.e. videoer.

  3. I add a db dependency to it and create a constructor function.

  4. 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.

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.

#programming #go