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.

6
  • How would you know to use SubModuleFactory in moduleB? Theoretically modules should be developed somewhat separately from one another. Commented Mar 20, 2015 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. This behavior of the module system seems quite bizarre and sloppy. It's essentially backflow through the dependency chain. Commented Mar 20, 2015 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. Commented Mar 20, 2015 at 17:49
  • You could consider this a bug. See: stackoverflow.com/questions/14909474/… Commented Mar 20, 2015 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. Commented Mar 20, 2015 at 20:59

1 Answer 1

0

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

Sign up to request clarification or add additional context in comments.

2 Comments

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.
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.