Reputation: 17724
I have a class that needs to use Dependency Injection (using Guice), but is currently instantiated by JAXB, so obviously nothing is injected. Any idea on how to fix this problem / tell JAXB to use Guice's Injector as object factory?
Thanks for any hint on this!
Upvotes: 0
Views: 290
Reputation: 127961
tell JAXB to use Guice's Injector as object factory
I don't think it is possible. The closest thing you can get is on-demand injection, that is, injection in already existing object; this will work, obviously, only for injectable fields and methods, not constructors.
By the way, JAXB classes usually represent data, don't they? Then they really should not have any dependencies because this is likely a violation of single responsibility principle - data classes should only contain and transfer data, nothing more. Move your logic code out of JAXB classes to separate classes which operate on JAXB classes. Then you can use Guice to instantiate these "service" classes.
Upvotes: 0