How to disable auto-injector (magic discovery of injector types) in angularjs?

Angularjs has this nice feature of auto discovery of the providers based on a function arguments. For example, if I want to use $http in some function i would call it like that:

$inject.invoke(function ($http) {

});

Angularjs will "know" what are my dependencies. It will figure it out by reading my function's body and based on argument names it will know.

However there is a problem when you would like to minify your code. Minifier will change arguments names. That's why we should use this notation:

$inject.invoke(['$http', function ($http) {}]);

or this notation:

function Foo ($http) {}
Foo.$inject = ['$http'];

$inject.invoke(Foo);

We should always in the end minify our code. So we should avoid using this magic (first example) notation.

And now my problem:

I'm trying to minify my js code and angularjs cannot resolve a provider name. I can't find a place where i haven't specified .$inject = [...]. Now it just says: "Unknown provider a" and i don't know what function is it referring to.

Is it possible to turn off angularjs auto discover (auto-injector) of providers? I would test and repair my code before minifying.

So, I'm wondering how to disable this "magic" angularjs deduction. Since I always minify my code I want angularjs to yell at me when I will accidentally use this superheroic evil.

How to turn it off?

Just edit the source. Find 'function annotate', and replace the fn == 'function' block with something like this:

if (typeof fn == 'function') {
  console.log("Bad magic injection in "+fn.toString().replace(STRIP_COMMENTS, ''));
}

update:

If anyone needs this because of trying to minify, maybe here is another possible solution

ngmin. It is an AngularJS application minifier project.

Not sure if this help.

According to Igor Minar,

You should make something like this

factory('Phone', function($resource){ ... }))

to

factory('Phone', ['$resource', function($resource){ ... })])

Here is the official doc from Dev guide.

$inject Annotation

To allow the minifers to rename the function parameters and still be able to inject right services the function needs to be annotate with the $inject property. The $inject property is an array of service names to inject.

var MyController = function(renamed$scope, renamedGreeter) {
...
}
MyController.$inject = ['$scope', 'greeter'];

Care must be taken that the $inject annotation is kept in sync with the actual arguments in the function declaration.

This method of annotation is useful for controller declarations since it assigns the annotation information with the function

From 1.3.0-beta.6 onwards angularjs supports ng-strict-di option which can be used along with ng-app directive to disable auto-injection.

From Documentation

if this attribute is present on the app element, the injector will be created in "strict-di" mode. This means that the application will fail to invoke functions which do not use explicit function annotation (and are thus unsuitable for minification), as described in the Dependency Injection guide, and useful debugging info will assist in tracking down the root of these bugs