Expand Minimize

Use explicit dependency injection annotation in factories with strict DI enabled

When bootstrapping application in strict DI mode, use explicit annotation to inject dependencies in factories

CheckId NG1010704
TypeName UseExplicitDependencyInjectionAnnotationWithStrictDiEnabledInFactories
Severity CriticalError
Type Service

When bootstrapping application in strict DI mode, you have to use explicit annotation to inject factories in services. Without it, your application will break on runtime.

Bad practice (no explicit annotation used for injecting dependencies into a factory used in an application bootstrapped in strict DI mode)

angular
    .module('app')
    .factory('dataService', function($http) {
        // ...
    }
);

angular.bootstrap(document, ['app'], {
    strictDi: true
});


Good practice
angular
    .module('app')
    .factory('dataService', ['$http', function($http) {
        // ...
    }]
);

angular.bootstrap(document, ['app'], {
    strictDi: true
});

Disclaimer: The views and opinions expressed in this documentation and in SPCAF do not necessarily reflect the opinions and recommendations of Microsoft or any member of Microsoft. SPCAF and RENCORE are registered trademarks of Rencore. All other trademarks, service marks, collective marks, copyrights, registered names, and marks used or cited by this documentation are the property of their respective owners.