I have a Wicket Web Page where I create a new Object of class A:
A a = new A(User u);
In A I would like to have setter injection, however this is actually not done. I have heard that one must provide an empty constructor but how is it possible to have also a non – empty constructor with setter injection?
I’m not familiar with Wicket, but I assume that you’ve got various things on your Wicket web page annotated with
@Inject, yes?So, you have a few options; in order of preference:
@Injecting yourUser, one option is to annotate the constructor ofAwith@Injectand then in your page, just@Injecteither anAor aProvider<A>into web page.@Injectinto your web page aMembersInjector<A>(call itaMembersInjector) and then after you create yourAobject callaMembersInjector.injectMembers(a)to cause all the setter injection to happen.@Injectinto your web page theInjectorand callInjector.injectMembers(a)after you create yourA.