From: Joel VanderWerf Date: 2004-11-16T03:33:21+09:00 Subject: Re: [ANN] MinDI: Minimalist Dependency Injection Avi Bryant wrote: > Joel VanderWerf wrote: > > >>The example from Jim Weirich's article would look like this in MinDI: >> >> class JWApplicationContainer >> extend MinDI::Container >> >> logfilename { "logfile.log" } > > >> quotes { StockQuotes.new(error_handler, logger) } > > >> end > > > Forgive me for being dense, but once you've gone this far, is there > any particular reason not to simply write: > > class JWApplicationContainer > def logfilename() "logfile.log"; end > > ... > > def quotes > @quotes ||= StockQuotes.new(error_handler, logger) > end > > ... > end > > and so on? I think the win in simplicity probably outweighs the extra > few characters you have to type... I forgive you :) That reaction was exactly the initial reaction that DI provoked in me and which I wrote up in [ruby-talk:120214]. The style that you suggest is what I've used in my own code, and it took Jim's article to see that it was really a form of DI. I'm not yet sure whether a more explicit DI (Arrow, or MinDI) will replace that style for me--I haven't actually used it in an application. It probably depends on how much I use the other service models besides singleton (e.g., #quotes, above) and prototype (#logfilename, in the way you defined it). In that case, DI may be a useful abstraction layer that saves more than typing.