AutoInjector.js: Automatic Dependency Injection for Angular

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?

3 Likes

looks interesting have to test it later.

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?

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

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