Found a good explanation of Dependency Injection, one of the pillars of CDI.
Of course, the original text by Martin Fowler2 is also well worth the read, but if you want to get into details of JEE, [1] is very good.
It works great, of course sometimes I screw it up, and then I get errors that need to be resolved, for instance:
org.jboss.weld.exceptions.DeploymentException: Exception List with 8 exceptions: Exception 0 : org.jboss.weld.exceptions.DeploymentException: WELD-001443: Pseudo scoped bean has circular dependencies. Dependency path: - Managed Bean [class com.mrbear.OrderService] with qualifiers [@Any @Default], - [BackedAnnotatedParameter] Parameter 1 of [BackedAnnotatedConstructor] @Inject public com.mrbear.OrderService(AddressService, x, y, z), - Managed Bean [class com.mrbear.AddressService] with qualifiers [@Any @Default], - [BackedAnnotatedParameter] Parameter 11 of [BackedAnnotatedConstructor] @Inject public com.mrbear.AddressService(a, b, c, d, e, f, g, h, I, j, OrderSupplier), - Managed Bean [class com.mrbear.OrderSupplier with qualifiers [@Any @Default], - [BackedAnnotatedParameter] Parameter 7 of [BackedAnnotatedConstructor] @Inject public com.mrbear.OrderFactory(a, b, c, d, e, f, CityTownVillageSearchService), - Managed Bean [class com.mrbear.CityTownVillageSearchService] with qualifiers [@Any @Default], - [BackedAnnotatedField] @Inject private com.mrbear.CityTownVillageSearchService.OrderSupplier, - Managed Bean [class com.mrbear.OrderFactory] with qualifiers [@Any @Default] at org.jboss.weld.bootstrap.Validator.reallyValidatePseudoScopedBean(Validator.java:924) at org.jboss.weld.bootstrap.Validator.validatePseudoScopedInjectionPoint(Validator.java:971) at org.jboss.weld.bootstrap.Validator.reallyValidatePseudoScopedBean(Validator.java:933) at org.jboss.weld.bootstrap.Validator.validatePseudoScopedInjectionPoint(Validator.java:971) at org.jboss.weld.bootstrap.Validator.reallyValidatePseudoScopedBean(Validator.java:933) at org.jboss.weld.bootstrap.Va
Funnily enough, circular dependencies seemed to work fine when using Enterprise Beans or some such. I guess it depends a little on the implementation.
References
- [1] JBoss Weld Reference - Chapter 4. Dependency injection and programmatic lookup
- https://docs.jboss.org/weld/reference/1.1.0.Final/en-US/html/injection.html
- [2] MartinFowler.com - Inversion of Control Containers and the Dependency Injection pattern
- https://martinfowler.com/articles/injection.html