|
As it stands there is no suitable scope provided by CDI which would fulfill both requirements:
-
The need to cache the ValidatorFactory and Validator. In particular the former is important, because building the factory takes quite some time. It is also on the factory level metadata in Hibernate Validator is cached. Recreating the ValidatorFactory would mean that bean metadata would need to be re-calculated each time
-
Module based isolation in a multi module based EAR application. This implies that each EJB jar can have its own ValidatorFactory and Validator
CDI 2.0 has the introduction of a ModuleScoped/EarScoped on its roadmap. Such a new scope is most likely the best solution for our case.
For a solution using the current latest CDI version (1.2), an approach could be to implement a custom scope (using the appropriate CDI SPI) which takes care of creating the proper isolation. This needs further investigation on how it could be implemented.
|