Expand Minimize

Use explicit dependency injection annotation in module configs with strict DI enabled

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

CheckId NG1010203
TypeName UseExplicitDependencyInjectionAnnotationWithStrictDiEnabledInModuleConfigs
Severity CriticalError
Type Module config

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

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

angular
    .module('app')
    .config(function($routeProvider) {
        // ...
    }
);

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


Good practice
angular
    .module('app')
    .config(['$routeProvider', function($routeProvider) {
        // ...
    }]
);

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.