Why is injecting @Bean from different modules allowed? #1214
-
Hey there, my company decided to use modulith for a Greenfield project, and I am all for it and learning new stuff. We have setup our project and started playing around with it, the I am trying to find info online and in the discussion here, but not finding much unfortunately. Is this an intended feature, or is there a way to disable such injections? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I've created an example project that mirrors our setup to show case the issue in question: https://github.com/alampada/modulith-beans/blob/main/src/main/kotlin/com/example/modulith/beans/a/DependantService.kt In our test, |
Beta Was this translation helpful? Give feedback.
-
Spring Modulith's dependency verification operates on a type level, not on bean instances. Bean instance references into other modules is not something wrong per se, as it's natural for one module to invoke another module directly. Also, we can't constrain references to other beans, as we're not even operating on a I guess we can explore the idea of constraining the injection of foreign module instances, but currently that's out of scope. |
Beta Was this translation helpful? Give feedback.
Spring Modulith's dependency verification operates on a type level, not on bean instances. Bean instance references into other modules is not something wrong per se, as it's natural for one module to invoke another module directly. Also, we can't constrain references to other beans, as we're not even operating on a
BeanFactory
but sole type references.I guess we can explore the idea of constraining the injection of foreign module instances, but currently that's out of scope.