Re:Scrap Your Cake Pattern Boilerplate: Dependency Injection...
by paf31 on Monday October 28, 2013 @06:45PM
(#6630358)
I'm not sure I understand the concern regarding the approach using implicits. Sure, you need to add an extra implicit method parameter to each method that requires the dependency, but in the reader approach, every same method needs to be written in the reader monad. In fact, they're really the same concern, since the reader monad instance is just doing the work of threading what would have been implicit in the first place.
[ Parent
| on HN ]
Re:Scrap Your Cake Pattern Boilerplate: Dependency Injection...
by paf31 on Monday October 28, 2013 @06:47PM
(#6630372)
Sorry, now I see it - it enables better type inference. Please ignore :)
Re:Scrap Your Cake Pattern Boilerplate: Dependency Injection...
by handler on Monday October 28, 2013 @06:51PM
(#6630390)
yeah, it is still a similar amount of overhead in typing
Re:Scrap Your Cake Pattern Boilerplate: Dependency Injection...
by jarhart on Monday October 28, 2013 @07:43PM
(#6630660)
Actually it's not. Only the primitive readers have similar "overhead" as with the implicits approach. Most of the readers are defined by mapping or flatMapping over the primitives (either explicitly or with comprehensions). With the implicits approach all of the "injected" methods need to declare the dependency via the implicit parameter. With the reader approach, only the primitives have to declare it. Compare the implicits version of UserInfo to the reader version. UserRepository doesn't appear anywhere in the signatures of the reader version.