November 2018
Intermediate to advanced
346 pages
8h 12m
English
Now that RegisterHandler requires an abstract dependency, we need to ensure that the dependency has been set by applying constructor injection, as shown in the following code:
// NewRegisterHandler is the constructor for RegisterHandlerfunc NewRegisterHandler(model RegisterModel) *RegisterHandler { return &RegisterHandler{ registerer: model, }}
With constructor injection applied, our RegisterHandler is less coupled to the model layer and our external resources (database and upstream service). We can leverage this looser coupling to improve and extend the test of our RegisterHandler.
Read now
Unlock full access