From: Jamis Buck Date: 2005-04-14T07:34:44+09:00 Subject: Re: Needle and Parameterized Services On Apr 13, 2005, at 2:19 PM, Rob Lally wrote: > A user of the framework would write > > mapr.register_statement(:select_person_by_id) do |id| > "SELECT * FROM person WHERE id = #{id}" > end > > Under the covers this stores this block in a needle registry. In order > to be able to call the service with a parameter it would need to have > c and p at the start of the block parameter list. > > At the moment I'm wrapping this block under the cover with another > block > > def register_statement(name, &statement) > @registry.statements.register(name, :model => :prototype) {|c, > p, *args| statement.call(*args) } > end > > Which works fine but feels a bit off. > Ah, I understand now. Yah, currently there is no option to prevent those parameters, so wrapping it as you did above is about your only option. I don't know how I feel about adding an option to "turn off" the c/p parameters. I know DI isn't a hugely popular approach in the Ruby world, but...anyone out there have an opinion on this matter? Personally, I think I'd lean towards just having consumers of Needle use adapters of one kind or another to change the interface, as you did above. It's an honorable and tried design pattern. What about it "feels a bit off" to you? Maybe that would help change my opinion. :) - Jamis