You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Andreas Petersson <an...@petersson.at> on 2009/02/21 12:48:30 UTC

request: make GuiceProxyTargetLocator public

Hello!
(this post went to the guice + the wicket mailing list)

I would really like GuiceProxyTargetLocator to have a public 
constructor. Currently it is package-access.
Furthermore findBindingAnnotation  should be made public static
I had to create a org.apache.wicket.guice.GuiceProxyTargetLocator2.cheat 
class + method in my codebase for  to get around the limitation.

My usecase:
I still had  problems using guice-injected members in serializable 
classes. Matej Knopp gave me some helpful hints on how to handle this.

i have somewhat solved it, using GuiceProxyTargetLocator .

AdminDao just a two - method interface of which happens to be 
implemented by a handful of DAOs. It is injected in factories, which in 
turn construct the Iterator. (not using @Inject in this case)

    public CommonIterator(AdminDao dao) {
        final Class<?> type = dao.getClass().getSuperclass();
        this.dao = (AdminDao) LazyInitProxyFactory.createProxy(type, 
GuiceProxyTargetLocator2.cheat(type,null));
    }

Since i am not using a BindingAnnotation in this specific case, its ok 
to pass null. Otherwise, i would be forced to re-implement 
findBindingAnnotation - this could be made public static as well.

getSuperclass() is used to determine the "true" Type of the Class, 
because initially it is wrapped in a Guice Proxy object.
is there maybe a better - guicy- way of obtaining this information from 
the dao instance? Is it true that Guice will always return a proxy- if 
not i will end up with a Class<Object> instance, which will break 
createProxy.

-----------
using my approach its impossible to use CommonIterator outside of a 
wicket application ( Batch jobs) - since there i do not have a 
WicketApplication initialized. So i'm not too happy about the solution.

This all feels messy, so i thought of how i think it could work - a more 
robust approach would be the following:

When Guice injectes into serializable Classes and a Wicket Application 
is present, modify Guice in a way that it returns 
LazyInitProxyFactory.createProxy instances, so that i do not have to 
worry about this. I think this would be a serious change to the guice 
api, a sort of instantiationChain in the injector, in which the wicket 
app could register itself. Or is there already a mechanism in place that 
allows me to hook into the instantiation and obtian the information 
where the object is being injected into?

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


Re: request: make GuiceProxyTargetLocator public

Posted by "Dhanji R. Prasanna" <dh...@gmail.com>.
Guice will not always return a proxy. You should not rely on this behavior.

Dhanji.

On Sat, Feb 21, 2009 at 10:48 PM, Andreas Petersson
<an...@petersson.at> wrote:
>
> Hello!
> (this post went to the guice + the wicket mailing list)
>
> I would really like GuiceProxyTargetLocator to have a public
> constructor. Currently it is package-access.
> Furthermore findBindingAnnotation  should be made public static
> I had to create a org.apache.wicket.guice.GuiceProxyTargetLocator2.cheat
> class + method in my codebase for  to get around the limitation.
>
> My usecase:
> I still had  problems using guice-injected members in serializable
> classes. Matej Knopp gave me some helpful hints on how to handle this.
>
> i have somewhat solved it, using GuiceProxyTargetLocator .
>
> AdminDao just a two - method interface of which happens to be
> implemented by a handful of DAOs. It is injected in factories, which in
> turn construct the Iterator. (not using @Inject in this case)
>
>    public CommonIterator(AdminDao dao) {
>        final Class<?> type = dao.getClass().getSuperclass();
>        this.dao = (AdminDao) LazyInitProxyFactory.createProxy(type,
> GuiceProxyTargetLocator2.cheat(type,null));
>    }
>
> Since i am not using a BindingAnnotation in this specific case, its ok
> to pass null. Otherwise, i would be forced to re-implement
> findBindingAnnotation - this could be made public static as well.
>
> getSuperclass() is used to determine the "true" Type of the Class,
> because initially it is wrapped in a Guice Proxy object.
> is there maybe a better - guicy- way of obtaining this information from
> the dao instance? Is it true that Guice will always return a proxy- if
> not i will end up with a Class<Object> instance, which will break
> createProxy.
>
> -----------
> using my approach its impossible to use CommonIterator outside of a
> wicket application ( Batch jobs) - since there i do not have a
> WicketApplication initialized. So i'm not too happy about the solution.
>
> This all feels messy, so i thought of how i think it could work - a more
> robust approach would be the following:
>
> When Guice injectes into serializable Classes and a Wicket Application
> is present, modify Guice in a way that it returns
> LazyInitProxyFactory.createProxy instances, so that i do not have to
> worry about this. I think this would be a serious change to the guice
> api, a sort of instantiationChain in the injector, in which the wicket
> app could register itself. Or is there already a mechanism in place that
> allows me to hook into the instantiation and obtian the information
> where the object is being injected into?
>
> --~--~---------~--~----~------------~-------~--~----~
> You received this message because you are subscribed to the Google Groups "google-guice" group.
> To post to this group, send email to google-guice@googlegroups.com
> To unsubscribe from this group, send email to google-guice+unsubscribe@googlegroups.com
> For more options, visit this group at http://groups.google.com/group/google-guice?hl=en
> -~----------~----~----~----~------~----~------~--~---
>
>

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