Me
About
Gallery
Company
Girl


Projects
Ruby on Rails
Basecamp
Highrise
Backpack
Campfire
Ta-da List
Writeboard


More
Feed
Archives

November 14, 19:54

Rails on the Needle: Let's inject?

Jamis Buck has an incredible detailed exploration of how an dependency injected world would look for Rails. We could be cute and call it Rails on the Needle, but we won't — the metaphors are already fairly fuzzy.

I'm much intrigued by the whole dependency injection game. I've been following along from the sideline since JAOO '03 where I hung for a while with ThoughtWorkers Hammett and Aslak for chats about Ruby, testing, and of course Inversion of Control/Dependency Injection talks. Hammett introduced it as the Hollywood Principle and while fascinated, I wasn't really seeing the applicability at the time.

Martin Fowler's defining article on IoC Containers and the DI pattern brought all the concepts into focus, but I still wasn't really feeling the hurt that this approach would be solving in any of my Ruby work.

I am now. Writing functional tests for Basecamp is at least a little painful when there's no easy way to automatically inject mocks for my GatewayService (talking to Authorize.net) and my ActionMailer. The latter is getting souped up for better testing in the next release (so you don't even need a mock), but I'm still getting the picture. DI is great for injecting mocks in hard-to-get-to places.

But I've never been comfortable with the explicit registry lookups or method assigns. Especially for class methods, like Account.find_all. So that turned me off Jamis' first proposal. But a few talks with Dave Thomas brought up the idea of transparent DI:

So I suggested to David that we could make Rails more explicit. Rather than having some random instance variable containing the model’s class, we could declare that such-and-such a class represents a model that the controller is using, but have that class actually injected by the framework.

I like this idea a lot. It's basically business as usual with DI for free. So you wouldn't even have to choose whether to do DI or not up front. Just as soon as you're feeling the pain, you start injecting.

So I got the hots for this proposal. The major thing still holding me back is what it'll do to the complexity of the internals of Rails. I think it'll even decrease the amount of code used, but the conceptual complexity will go up. I'm just starting to get to terms with DI, so I can definitely relate to those fears that other contributors have voiced.

But I think the proposal Jamis has put together goes a long way to dispel those fears. It's centered purely around wiring controllers and models together and if you're uncertain of the value of injecting mocks, you can just not use it. And the world will spin around like it did yesterday.

Yes, I'm feeling good about it. And Jamis is about as smart a developer as they come, so when he's excited about something like Rails on the Needle, I'd be a fool not to listen really closely.


Challenge by hammett on November 14, 22:04

Hiya!
AFAIK I'm not a ThoughtWorker :-)

Its amazing, and I have to tell you that right this moment I'm working on something I called Castle on Rails (a small piece of the castle project - first draft available at http://www.castleproject.org ) which is exactly what you have described. The Castle Microkernel will inject all necessary models/services in the controller and the view...

Wow! For those who have seen the Waking Life film: once the knowledge is out there, it seems that it can be captured... :-)

Cheers!

Challenge by hammett on November 14, 22:06

Oh, and you've confused me with Paul Hammant. We both came from Avalon, maybe thats the reason :-)

Challenge by Mark on November 15, 0:14

If you're still looking for an alternative name to "Rails on the Needle", I believe you need look no further than this line of yours:

Just as soon as you're feeling the pain, you start injecting

Hence, Morphine. :)

Challenge by Rob on November 15, 0:54

Rails is getting more and more tempting all the time. I am a Java guy, and thought that DI was one of the things that Rails was missing, to see it added and so cleanly looks great.

My excuses for not doing Rails work are fast decreasing ;).

Challenge by Jamis Buck on November 15, 2:17

Morphine...heh. I can see it now. A headline: "Morphine Makes Developers Super-Productive". :-P

Challenge by William Taysom on November 15, 16:34

"transparent DI"? Sounds like Aspect Oriented Programming to me.

Challenge by John Wilger on November 16, 15:15

I'll cast my vote for adding DI to Rails. The deciding factor for me is the ability to add AOPish functionality to the model. I'm often running into instances in a current project of mine where I need to have advice added to a certain attribute assignment on a model class that doesn't really belong in the model class itself.

For instance, the project I'm working on is a PM tool for eXtreme Programming (yes, I know about Jim's StoryCards project---this is more a personal project to teach myself Ruby/Rails). In the model, I have a Project class and a StoryCard class. Project has a #status attribute that uses a third class called ProjectStatus to contain various bits of meta-data about a status. One of these is ProjectStatus#is_closed, which allows me to define several statuses but have each of them considered a closed project (i.e., Complete, Cancelled, etc.).

I want to enforce at the model level that a StoryCard can not be assigned to a Project unless Project#status.is_closed == false. However, the checking for this really shouldn't be in the StoryCard model, because that requires StoryCard to have too much internal knowledge of Project/ProjectStatus.

Currently, I'm resorting to using StoryCard.module_eval inside the Project class definition to add the status checking logic to StoryCard so that the logic is, at least, in the same file as Project. This still has a bad code smell to it, though. With DI, I should be able to use the registry to intercept the calls to StoryCard#project_id= a lot more cleanly and simply add the advice that way.

Challenge by learn roulette strategies on May 08, 6:46

Please check some information in the field of casino game casino game http://www.juris-net.com/casino-game.html yahoo poker yahoo poker http://www.juris-net.com/yahoo-poker.html omaha poker omaha poker http://www.juris-net.com/omaha-poker.html strip poker pictures strip poker pictures http://www.juris-net.com/strip-poker-pictures.html gulf coast casinos gulf coast casinos http://www.juris-net.com/gulf-coast-casinos.html poker chip distributors poker chip distributors http://www.juris-net.com/poker-chip-distributors.html casino business plans casino business plans http://www.juris-net.com/casino-business-plans.html poker chip cases dallas poker chip cases dallas http://www.juris-net.com/poker-chip-cases-dallas.html rank of poker hands rank of poker hands http://www.juris-net.com/rank-of-poker-hands.html craps odds craps odds http://www.juris-net.com/craps-odds.html las vegas slot dealers las vegas slot dealers http://www.juris-net.com/las-vegas-slot-dealers.html casino in biloxi casino in biloxi http://www.juris-net.com/casino-in-biloxi.html free slot machine downloads free slot machine downloads http://www.juris-net.com/free-slot-machine-downloads.html video poker machines for sale video poker machines for sale http://www.juris-net.com/video-poker-machines-for-sale.html blackjack counting cards blackjack counting cards http://www.juris-net.com/blackjack-counting-cards.html craps table layout craps table layout http://www.juris-net.com/craps-table-layout.html gambling for a living gambling for a living http://www.juris-net.com/gambling-for-a-living.html barroom blackjack barroom blackjack http://www.juris-net.com/barroom-blackjack.html craps odds sheet craps odds sheet http://www.juris-net.com/craps-odds-sheet.html types of gambling types of gambling http://www.juris-net.com/types-of-gambling.html online gambling press online gambling press http://www.juris-net.com/online-gambling-press.html blackjack play card blackjack play card http://www.juris-net.com/blackjack-play-card.html blackjack counting blackjack counting http://www.juris-net.com/blackjack-counting.html how to count cards in blackjack how to count cards in blackjack http://www.juris-net.com/how-to-count-cards-in-blackjack.html keno wheel freeware keno wheel freeware http://www.juris-net.com/keno-wheel-freeware.html roulette game toy roulette game toy http://www.juris-net.com/roulette-game-toy.html roulette game gift roulette game gift http://www.juris-net.com/roulette-game-gift.html casino roulette blackjack slot machines casino roulette blackjack slot machines http://www.juris-net.com/casino-roulette-blackjack-slot-machines.html casey  blackjack computer complaints casey  blackjack computer complaints http://www.juris-net.com/casey%C2%A0%C2%A0blackjack%C2%A0computer%C2%A0complaints.html craps table jpg craps table jpg http://www.juris-net.com/craps-table-jpg.html strip blackjack free strip blackjack free http://www.juris-net.com/strip-blackjack-free.html craps wallpaper craps wallpaper http://www.juris-net.com/craps-wallpaper.html always win in roulette always win in roulette http://www.juris-net.com/always-win-in-roulette.html oil pump jacks black and white photos oil pump jacks black and white photos http://www.juris-net.com/oil-pump-jacks-black-and-white-photos.html bon temps roulette bon temps roulette http://www.juris-net.com/bon-temps-roulette.html - Tons of interesdting stuff!!!

Challenge by ivan on June 04, 12:12

Sorry for my links
older women and younger men older moms mature nudists photos mature spunker mature gallerys mature gallerys classic mature mature nudists photos mature spunker mature video older women and younger men classic mature mature gallerys mature spunker mature anal mature nud3 pics free naked older women mature ladies in lingerie lyrics to older country songs free naked older women older women and younger men mature women stories lyrics to older country songs free thumbnail pictures of older women mature amature mature ladies in lingerie mature living mature anal older moms mature ladies in lingerie older moms mature nud3 pics mature gallerys mature living mature nud3 pics mature spunker mature spunker classic mature mature nudists photos mature nud3 pics

Challenge by angel on June 04, 20:08

Hi. This is my links.
xyx creampies mature creampies free creampie pics free free creampie video free anal creampie movies creampie video store free creampie thumbnails wife oral creampies free creampie video free creampie video free anal creampie movies hairy creampie creampie pussies japanese creampie links teen anal creampies creampie video clips free creampie pics free japanese creampie links creampie ass free creampie video creampie video store wife oral creampies cum creampie xyx creampies xyx creampies cum creampie wife oral creampies creampie ass free creampie pics free xyx creampies japanese creampie links creampies movies creampie pussies free creampie video creampie t9p cum creampie teen anal creampies free creampie video teen anal creampies free creampie pics free

Challenge by nik on June 05, 17:32

Hello. I am new here. It is very interesting.
mature men galleries mature women nud3 older women younger men mature nud3 women mature babes older men younger women mature wives free mature s3x mature women nud3 mature wives mature nud3 women dating mature women free mature old naked women mature women t9p free mature p0Rn older women younger men mature wives dating mature women mature men galleries free mature s3x mature women in stockings mature amateur dating mature women dating mature women mature women t9p mature wives older women younger men older women younger men mature men galleries mature wives mature amateur mature over 50 mature women in stockings free mature s3x mature women t9p mature babes mature wives mature over 50 mature nud3 women

Challenge by den on June 05, 21:21

Hi. This is my links.
cheerleader panty pics pantyhose links.com leggs pantyhose free panty movies leggs pantyhose pictures of men in pantyhose leggs pantyhose mature pantyhose pics pictures of women in crotchless pantyhose men's pantyhose teens in panties free links mature ladies in pantyhose men caught wearing pantyhose cheerleader panty pics visible panty lines pics teens in panties free links pictures of men in pantyhose visible panty lines pics pictures of women in crotchless pantyhose young girls in panties pictures of women in crotchless pantyhose pantyhose links.com used pantyhose nonnud3 teens in pantyhose teens in panties free links panty fetish young girls in panties young girls in panties free panty movies mature pantyhose pics young teens in bra panties pictures of men in pantyhose pictures of men wearing pantyhose satin panty galleries mature ladies in pantyhose pictures of women in crotchless pantyhose young girls in panties leggs pantyhose pictures of men in pantyhose men's pantyhose

Challenge by jon on June 06, 11:41

Sorry for my links
mature pic gallery mature hardcore links mature glamour black older ladies thumbs gallery older women mature mistress older black women mature nudists older women stories mature big tits mature pantyhose pictures mature pic gallery how to meet older women mature pantyhose pictures older women stories older women stories free older women galleries mature pic gallery young girls older men young girls older men mature nudists mature big tits naked old women thumbs how to meet older women free older women galleries naked old women thumbs young girls older men mature pantyhose pictures mature big tits mature big tits older 1esbians how to meet older women mature asian women mature index mature pantyhose pictures mature mistress mature mistress mature women over 40 older 1esbians free older women galleries

Challenge by juju on June 08, 0:18

Hi. This is my links.
white pantyhose cheerleader panty pics mature pantyhose pics mature women in pantyhose office girls in nylons white pantyhose satin panty galleries panty post celebrities in pantyhose girls in nylons free wet panty celebrities in pantyhose office girls in nylons cheerleader panty pics celebrities in pantyhose wet pantyhose free wet panty free wet panty white pantyhose men's pantyhose panty post free teen panties pantyhose images men's pantyhose satin panty galleries panty post wet pantyhose men caught wearing pantyhose men caught wearing pantyhose white pantyhose free teen panties panty thumbnails white pantyhose men caught wearing pantyhose winnie-cooper pantyhose mature ladies in pantyhose celebrities in pantyhose panty fetish wet pantyhose office girls in nylons

Challenge by atmor on June 08, 4:34

Sorry for my links
pantyhose men free pantyhose pics pantyhose fetish pantyhose pic gallery wolford pantyhose pantyhose men pantyhose men pantyhose fetish crotchless pantyhose shiny pantyhose pantyhose pic gallery shiny pantyhose free pantyhose pics free panties panty girls silkies pantyhose little school girls panties teens in pantyhose wolford pantyhose crotchless pantyhose pantyhose foot gallery free pantyhose sites pantyhose fetish free panties silkies pantyhose pantyhose fetish men in panty pics men in panty pics teens in pantyhose pantyhose fetish teens in pantyhose crotchless pantyhose little school girls panties free pantyhose pics free pantyhose sites bra and panty pics free pantyhose pics teen panty pictures shiny pantyhose panty girls

Challenge by poker rules on June 21, 0:10

In your free time, check the pages on poker rules poker rules http://poker-rules.zindagi.us/ .