I've known this for so long now, that I've sort of forgotten that it can nail new people in the ass.
The last one registered with the name wins - which means you have to be mindful about how you name things, or prefix/namespace them.
The other issue that can happen, is once something is defined as a dependency somehow in your app - every other module can use it, even if it was not an explicit dependency.
When you run your app, module b can access cFactory, even though you never defined it as a module dependency.
However, when writing my unit tests - I'll only do a beforeEach(module('b')) - in which case, the unit test would blow up and fail about not knowing about cFactoryProvider. Helps keep me honest about keeping my module dependencies in check and being mindful about where I'm getting things from, even if when running as an app - that sort of goes out the window.
It seems there is a global pool of objects for all injections, and that if we load a module with the same name it gets silently overwritten even if it does something completely different. this is apparently a feature and not a bug and is meant for testing. Have a look at this post -> http://victorsavkin.com/post/102965317996/angular-2-bits-unified-dependency-injection Angular 2 will fix this using hierarchical injectors (it looks like it will be transparent for us)
13
u/e82 May 22 '15
I've known this for so long now, that I've sort of forgotten that it can nail new people in the ass.
The last one registered with the name wins - which means you have to be mindful about how you name things, or prefix/namespace them.
The other issue that can happen, is once something is defined as a dependency somehow in your app - every other module can use it, even if it was not an explicit dependency.
When you run your app, module b can access cFactory, even though you never defined it as a module dependency.
However, when writing my unit tests - I'll only do a beforeEach(module('b')) - in which case, the unit test would blow up and fail about not knowing about cFactoryProvider. Helps keep me honest about keeping my module dependencies in check and being mindful about where I'm getting things from, even if when running as an app - that sort of goes out the window.