Expand Minimize

Use explicit dependency injection annotation in services with strict DI enabled

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

CheckId NG1010703
TypeName UseExplicitDependencyInjectionAnnotationWithStrictDiEnabledInServices
Severity CriticalError
Type Service

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

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

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

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


Good practice
angular
    .module('app')
    .service('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.