Hi Andreas,

My guess is that the GuiceComponentInjector proxies are "detached" when the page is serialized. The last page (or the last N pages) are kept in memory by wicket (I think, last I checked was some years ago).

Checking ...
Yes, see LazyInitProxyFactory and its nested class JdkJHandler (which is used for injected interfaces).
The proxy is replaced on serialization.

Somehow I always thought the proxies were also detached when the page is detach()-ed. Guess not :-)

Met vriendelijke groet,
Kind regards,

Bas Gooren

Op 27-6-2013 23:37, schreef Andreas Lundblad:
On Thu, Jun 27, 2013 at 11:25 PM, Bas Gooren <b...@iswd.nl> wrote:
Hi Andreas,

When your validator fails, you remain on the FormPage. A quick debug session
shows me that the injected IService remains the same accross requests.
I've seen this too. I thought that this didn't matter since, as you
said: "The GuiceComponentInjector which is set-up in the wicket
application injects proxies".

The fix for your problem is simple, and a best practice anyway: inject
Provider<EntityManager> in your service.

It's a best practice since the service does not know the "scope" of the
entitymanager, all it knows is that the entitymanager has a different
lifecycle; Your service may be instantiated and kept around for the time
your app is running, but could also be instantiated on the fly when needed.
That's one of the reasons why Provider<> was invented: if the scope is
different, a provider allows you to nicely deal with it.

In case you are not familiar with providers: it has no negative side-effects
in terms of performance.
The guice-persist module binds the EntityManager per request, so all calls
to Provider<EntityManager> while in the same request will yield the exact
same EntityManager instance.



PS See https://code.google.com/p/google-guice/wiki/InjectingProviders (header 
"Providers for Mixing Scopes").
Thank you Bas for this excellent answer. Much appreciated.

-- Andreas Lundblad

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org


Reply via email to