Nik Kolev on 24 Jul 2012 22:18:54 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: followup to PhillyETE: dependency injection without the gymnastics (tony morris on monads)


Here's a post i read recently that discusses a "non-enterprisey"/roll-your-own-kinda approach to DI: http://aphyr.com/posts/240-configuration-and-scope

On Tue, Jul 24, 2012 at 11:51 PM, Mat Schaffer <mat@schaffer.me> wrote:
I still don't get monads, but I was reading objects on rails today and thought this was a interesting take on Ruby DI: https://gist.github.com/3174258

Basically uses a simple callable object as a factory for other models. Or you can write one in to change behavior (e.g., for test isolation).

-Mat

about.me/matschaffer



On Tue, Jul 24, 2012 at 7:07 PM, Dustin Getz <dustin.getz@gmail.com> wrote:
At PhillyETE, Tony Morris gave a talk "dependency injection without the gymnastics"[1]. (To establish a common language: "dependency injection" is when we structure our functions to take dependencies by argument, instead of hardcoding them, so we can swap implementations e.g. to mock them.)

Tony's thesis is that "injecting dependencies by argument is cumbersome" and "traditional enterprise dependency injection solutions are shitty" (this is questionable to me?) and he goes on to provide monadic Scala code to solve this problem. I've reimplemented it in python to better understand, and I question his assertion, and don't really see the value-add of pass-by-arguments because deeper in the callstack when we get to business logic, we have to pass dependencies by argument anyway.

to help understand what he's talking about, here is a 30 line python program that demonstrates using reader-monad to inject dependencies per Tony's talk. (way easier to comprehend than the wall of code in the slides): https://gist.github.com/3172127#gistcomment-379014

what approaches to DI have you guys seen in the wild? any thoughts as to why Tony asserts that a monadic solution is superior to traditional solutions? i'm really not seeing the value-add here, but he's a smart guy and quite assertive about the superiority of a monadic approach.