views:

258

answers:

3

Are there any existing modern-day programming languages that explicitly have dependency injection as a language feature, and if so, are there any examples of how such programming languages use their syntax to separate program dependencies from their concrete implementations?

(Please Note: I'm not looking for an DI/IOC framework--I'm actually looking for a programming language that actually has this feature built into the language).

+3  A: 

I don't mean to sound like a jerk, but every OO language supports dependency injection. No special syntax is required. Just construct your object with their dependencies (or set their dependencies later).

You can actually wire up all your dependencies somewhere near the top of the program - not necessarily main(), but close to the top.

Daniel Yankowsky
I'm not looking for a programming language that lets you implement dependency injection, I'm actually looking for a language that says "I want to create an IFoo" and then the compiler/runtime decides what gets created without specifying the concrete classes at compile time.
plaureano
Ah, I think you're looking for language support for autowiring or auto service discovery. My mistake.
Daniel Yankowsky
+3  A: 

Noop supposedly does this, but I haven't seen the language specification (my patience ran out before I found it).

starblue
The injection proposal for noop is discussed at http://code.google.com/p/noop/wiki/Features and http://code.google.com/p/noop/wiki/ProposalForNewableVsInjectableThe proposal for noop injection support will be based on Google's Guice framework for injection. http://code.google.com/p/google-guice/
Kaka Woef
It looks like Noop is a dead language. There hasn't been any activity in the Noop language forum for quite a while now.
plaureano
+6  A: 

You won't find dependency injection as a language feature, as it's generally seen as a design pattern. Design patterns arise as workarounds for missing language features - for example if you have first class types as a language feature you don't need the factory pattern ( see Norvig's presentation ), if you have multi-methods as a language feature you don't need the double dispatch pattern.

The language feature for which DI is the design pattern is "parametric modules". See the discussion of modules vs DI relating to Gilad Bracha's language Newspeak

Pete Kirkham
And see also the discussion on "Design Patterns are Signs of Weakness in Programming Languages" -- http://www.oreillynet.com/onlamp/blog/2006/10/design_patterns_are_signs_of_w.html
Kaka Woef