From: Nikolai Weibull Date: 2005-09-27T02:08:26+09:00 Subject: Re: [ANN] My dependency-injection library Christian Neukirchen wrote: > Nikolai Weibull writes: > > OK. So Ruby has enough dependency-injection/inversion-of-control > > libraries as it is, but mine is quite different so I figured I’d > > post it. It’s about as simple as dependency-injection can possibly > > become and there’s no support for lifecycles, interception, or other > > framework stuff. Nor is there any support for parents, children, or > > other relatives, so keep it to yourself. > Interesting idea, but you are only pushing constants around? I’d like to think that we’re doing a bit more than that. > Can't we do that easier? Maybe. > > class Scanner > > def initialize(io) > > raise Error, "can only work with open io-ports" if io.closed? > > @io = io > > end > > end > > > class Error < ScriptError; end # Or something more creative, perhaps? > Scanner::Error = Error > > > class TC_Driver < Test::Unit::TestCase > > ⋮ > > end > > > So the idea is that under normal circumstances, ‘needs’ is just a > > circumvention for not using ‘require’ directly, but for trying times the > > dependency can be changed to something more suitable. > > I really fail to see the advantage of using this over manual require > and dependency setting. :-) Well, the thing is, what do you do when you have a compiler class class Compiler ⋮ raise Error, … ⋮ end that also ‘needs’ our error class? > I personally would expect a DI framework to at least provide a > singleton instantiation scheme, else it wouldn't make any sense to me > at all. Well, maybe so, but the idea of my library is that all you really need is to be able to bind constants to classes. It’s definitely not much, but I found that that was precisely what I was looking for. > Einstein once said "Everything should be made as simple as possible, > but not simpler". Or something to that effect, yes. (I have yet to find the actual source of this quotation. Not that I’m doubting that he said it, but I am wondering if he said/wrote it in English or German and if there was some context to it as well.) > I think anything more simple than Matz-DI is too simple. > > http://onestepback.org/articles/depinj/matz/index.html Perhaps, but again, all I was looking for is done by my library. I’m certainly not trying to force people to stop using needle or some other library (e.g., dissident). To me, needle is doing a bit too much and I seem to have a hard time reading your examples for dissident (how do you do namespacing in dissident?), so I haven’t given it a chance yet, nikolai -- Nikolai Weibull: now available free of charge at http://bitwi.se/! Born in Chicago, IL USA; currently residing in Gothenburg, Sweden. main(){printf(&linux["\021%six\012\0"],(linux)["have"]+"fun"-97);}