tags:

views:

85

answers:

3

I've been doing ColdFusion for 2 years, and I've always used ColdSpring for injecting dependency. I want to try to see if I can survive without them. What're the alternatives?

For singleton:

onApplicationStart() and inject services to Application scope?

For transient:

Factory pattern? XXXFactory.createXXX()? or... XXXService.createXXX()?

Please comment, and share your alternative.

+1  A: 
Aaron Greenlee
A: 

These are all great suggestions. My main goal lately when setting up the family of supporting services and whatnot has been to brace for caching and divorce the application code from the API's inner workings. Specifically, this translates into always using factories to generate transients and always having singleton services that receive requests from the application.

I don't think I can live without AOP anymore though. I've been able to solve so many surprise issues with layered interceptors that I should really build a small shrine at my desk to worship AOP from.

So, in summary, when building your own solution try to implement singleton services and transient factories. AOP is a huge bonus, but I couldn't tell you how to implement that. I'm a ColdSpring user, and thankful it does what it does!

Adam Bellas
What's your use case for AOP? thx
Henry
+1  A: 

There are certainly cases cases where a DI framework hides some code smells, say passing in a pile of parameters automagically. By doing things by hand, or at least knowing what doing so would entail you'll make your designs cleaner. It's probably a bit like learning C, even if you don't use it often it good stuff to know.

There's an intersting article about do-it-yourself DI here that focuses on Java but might be worth your while.

Paul Rubel