Hi,

On Wed, Jun 26, 2013 at 4:14 AM, 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
>

Don't be sceptic ;-)

Here is some code that has been used with Wicket 1.4 -
https://github.com/jolira/wicket-guicier.
You can use it or at least be inspired by it.


> 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
>

The first thing I'd try is to use custom IPageFactory.


> 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