I worked out this process:
http://software.danielwatrous.com/wicket-guice-including-unittests/

It enables unittests and may help you toward your goal.

Daniel


On Tue, Jun 25, 2013 at 7:14 PM, William Speirs <wspe...@apache.org> wrote:

> I think I know the answer before I ask, but is there any way to do
> constructor injection with Wicket? Say I have a web page and an email
> service. I need the email service in the web page. Now everyone is
> going to say, "Simply use field injection." That will work, but makes
> unit testing a real pain because now I have to setup injection for my
> unit test (or add additional methods to all of my pages so I can
> manually set these field, or additional constructors that set these
> fields). I should be able to unit test a class without needing
> injection, but instead passing mocks through the constructor.
>
> I feel like this is impossible in Wicket currently because the
> DefaultPageFactory is using reflection to create the page instances
> instead of the injector (Guice in my case). It would be easy enough to
> get the injector and call getInstance() to obtain a page instance. The
> problem is when you need to pass in parameters. There is no concept of
> parameters for a page other than what is passed via the constructor,
> so you cannot call something like setPageParameters because it doesn't
> exist. If using Guice, you could create an @Assisted injection, and
> have a factory.
>
> Has anyone tried creating this type of IPageFactory -- a
> GuicePageFactory? What kind of pitfalls would exist if I attempted
> such a thing? Am I being stupid and missing something? Thoughts?
>
> Thanks...
>
> Bill-
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
>
>

Reply via email to