cedric
04/03/2017, 9:31 PMgetPort()
function calls a function that also needs something from that config, but a different parametercedric
04/03/2017, 9:31 PMcedric
04/03/2017, 9:32 PMroberto.guerra
04/03/2017, 9:33 PMcedric
04/03/2017, 9:33 PMroberto.guerra
04/03/2017, 9:33 PMcedric
04/03/2017, 9:34 PMgetPort()
and say “Guice, give that function a Config
somehow, I don’t care"cedric
04/03/2017, 9:35 PMReader
blog posts irk me: because their authors are either unaware of these deficiencies or they are intentionally not disclosing them in an attempt to make Reader
appear as a silver bullet with no downsides. Either way, bad literature.roberto.guerra
04/03/2017, 9:35 PM@Inject
or @Autowire
all across the code base. That forces me to think explicitly about all these dependencies. With Spring, I normally wire them together using @Configuration
instead of polluting everything with spring annotations.roberto.guerra
04/03/2017, 9:36 PM@Services
and things auto-wired all over the place.roberto.guerra
04/03/2017, 9:36 PMroberto.guerra
04/03/2017, 9:37 PMcedric
04/03/2017, 9:37 PMcedric
04/03/2017, 9:37 PMgetPort()
depend on the Config
class.roberto.guerra
04/03/2017, 9:38 PMgetPort()
, you don’t go in and modify that , right?cedric
04/03/2017, 9:38 PMroberto.guerra
04/03/2017, 9:38 PMcedric
04/03/2017, 9:38 PMroberto.guerra
04/03/2017, 9:39 PMroberto.guerra
04/03/2017, 9:40 PMroberto.guerra
04/03/2017, 9:41 PMdependency passing
before, and googled it and it was just resolved to dependency injection
.cedric
04/03/2017, 9:42 PMcedric
04/03/2017, 9:42 PMReader
does and contrast it with dependency injectioncedric
04/03/2017, 9:43 PMgetPort()
, that’s part of being referentially transparent: all the parameters must be passed to the functioncedric
04/03/2017, 9:44 PMgetPort()
needs a Config
object. DI will inject that object directly in a field of the class, Reader forces you to pass it as a parameter (another downside by the way, now getPort()
is getPort(config: C) : Reader[C, Int]
)cedric
04/03/2017, 9:44 PMcedric
04/03/2017, 9:44 PMroberto.guerra
04/03/2017, 9:46 PMPersistenceContext
and I just added an extension function to it (getProperty), that way we just passed that down, and called context.getProperty
. What I didn’t like was that … well, I had to pass in a PersistenceContext
instead of just the explicit property I wanted.roberto.guerra
04/03/2017, 9:47 PMgetSomethingFromX(persistenceContext, request)
roberto.guerra
04/03/2017, 9:48 PMgetSomethingFromX(host, request)