AutoInjector.js: Automatic Dependency Injection for Angular


#1

Hey, I just released a library that solves the hassle of maintaining dependencies by scanning the code and injecting them automatically.

For example, the following:

app.controller('MyCtrl', function ($scope, 
                                   $timeout, 
                                   $state,
                                   $stateParams,
                                   $localStorage,
                                   $ionicPlatform,
                                   $ionicModal,
                                   $ionicPopup,
                                   LoginService,
                                   MessageService) {
    ...
});

… turns into:

app.controller('MyCtrl', $inject(function MyCtrl() {
    ...
}));

What do you think?


#2

looks interesting have to test it later.


#3

Is this actually worth it if you are concerned about performance? Seems like a relatively “heavy” task for something you could avoid by just using the includes yourself? Could you specify some performance benchmarks?


#4

Performance shouldn’t be affected too much because the injection happens only once per controller definition. I don’t have actual benchmarks yet though.


#5

Looks good, but i think minification / Uglify will be a problem