November 2018
Intermediate to advanced
346 pages
8h 12m
English
Have you ever written an object and injected a dependency that you knew was only going to have one implementation? Perhaps you have injected the database handling code into the business logic layer, as shown in the following code:
func NewMyLoadPersonLogic(ds DataSource) *MyLoadPersonLogic { return &MyLoadPersonLogic{ dataSource: ds, }}type MyLoadPersonLogic struct { dataSource DataSource}// Load person by supplied IDfunc (m *MyLoadPersonLogic) Load(ID int) (Person, error) { return m.dataSource.Load(ID)}
Have you ever added a dependency to your constructor for the sole purpose of mocking it out during testing? This is shown in the following code:
func NewLoadPersonHandler(logic LoadPersonLogic) *LoadPersonHandler { return
Read now
Unlock full access