0

I've been trying to optimise how I manage modules in a reasonable sized App and have come across a possible issue with dependencies.

As far as I can tell a module can access a service in another module even if there is no direct dependency.

Say we have an app module that depends on two modules moduleA and moduleB. Is it correct that moduleB should be able to access the dependencies of moduleA? This is what appears to happen in the fiddle I set up - https://jsfiddle.net/neridum/jfdsjhjo/

To me this means that you could have the issue that if moduleA was altered it could affect moduleB even though the two are not dependencies.

I may have gone about it the wrong way or have misunderstood something. Or it could be a limitation of the Angular module system.

Edit: There is a similar module issue in Angular regarding the naming collision - "Namespacing" services in AngularJS I think this is a slightly different issue as in addition to the naming collision there is also the issue of modules being available when they perhaps shouldn't be.

Community
  • 1
  • 1
Asta
  • 1,569
  • 13
  • 23
  • How would you know to use `SubModuleFactory` in `moduleB`? Theoretically modules should be developed somewhat separately from one another. – Explosion Pills Mar 20 '15 at 17:29
  • @ExplosionPills What if Modules A and B just happened to depend on factories with the same name in different modules? [Example showing that the system is broken](https://jsfiddle.net/ehqn318m/). This behavior of the module system seems quite bizarre and sloppy. It's essentially backflow through the dependency chain. – JLRishe Mar 20 '15 at 17:41
  • @ExplosionPills Rationally speaking, including two modules as dependencies in a third module should not cause them to pool their dependencies together (and possibly overwrite each other), but apparently that is what actually happens. – JLRishe Mar 20 '15 at 17:49
  • You could consider this a bug. See: http://stackoverflow.com/questions/14909474/namespacing-services-in-angularjs – Explosion Pills Mar 20 '15 at 18:10
  • @ExplosionPills Thanks for the link. I think this question could be treated as a duplicate of that one. To OP: Yes, as the answers to the other questions state, it's true that names on services, etc. are all pooled together within a dependency network, and if you have a reason to believe that could become an issue, the suggested solution is to use a prefix on the names of your services, to namespace them. – JLRishe Mar 20 '15 at 20:59
  • Thanks for the links. I think this is a slightly different issue although it is related to the namespacing problem. The use case here is that I have a utility module that several other modules can depend on. It would be too easy to forget a dependency which would be a problem if the module that was declaring the dependency was removed. – Asta Mar 22 '15 at 20:53

1 Answers1

0

Both modules should act independently , There should not be any necessity to access the others dependencies.

Rj-s
  • 484
  • 3
  • 7
  • 17
  • No, they should not need to access each others' dependencies, but Angular makes it so that they _can_ access each others' dependencies (and even overwrite them). That is the problem. – JLRishe Mar 20 '15 at 17:45
  • Yes, the issue I have is that one of the dependencies is a util service which I wanted to modularise better. It has methods that are used in several different modules which is what brought me to my issue. Currently it is a service on the main module. – Asta Mar 22 '15 at 20:37