preface - this is more a conceptual discussion rather than a "how-to". If there is a simple way to implement, then I would certainly be thankful for tips on how but I really want to gain insight on why/why not this isn't possible or a good idea. Any and all comments/constructive criticism is welcome.
property/setter-based dependency injection
new $injector APIs
# pseudo-code
postInjectionHook = 'init'
injectInto = (target)->
for key of target
if $injector/this.$has key
target[key] = $injector.get key
if target[postInjectionHook] is Function
target[postInjectionHook]()
simple controller example
angular.module 'app', []
.controller, 'SomeController', class SomeController
$http: undefined
$q: undefined
init: -> #do some work after we get our dependencies
elsewhere in angular-land
uiController = new SomeController
$injector.injectInto uiController
why?
I love the simplicity of javaScript. It's a very malleable, yet powerful language. However I don't think I'm the only developer that came from another programming language longing for certain features missing from javascript. As such, I utilize inheritance (I know OMG!!!) to structure many base-classes in my application development. Specifically all of my angular controllers inherit from key base classes (e.g. baseViewController, basePopupController, etc.).
Angular's forcing of constructor-based DI makes inheritance somewhat of a pain if I plan to extend beyond the base controller classes. The constructor arguments must be carried over to any subclasses. I wish there were a way to allow different types of dependency injection.