You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Edgar Merino <do...@gmail.com> on 2008/10/16 01:42:06 UTC
Guice: injection outside Component
Hello again,
using guice's @Inject inside any component works perfect, however
I've got some objects (not components) that reside inside a component
and need an injected service, since wicket-guice handles only injection
inside components, I'm getting null services:
public class Instantiator {
@Inject Service service;
public Panel getPanel(String id) {
Author author = service.findAuthor("me");
return new SomePanel(id, author);
}
}
I need to fetch the "Author" outside the panel, the panel is not able to
fetch it. One approach might be to get the service from the Application,
but I do not want to do this since I don't want the application to know
about my Instantiator class, is there a better approach to accomplish
what I need? thanks in advance.
Edgar Merino
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Guice: injection outside Component
Posted by Igor Vaynberg <ig...@gmail.com>.
or use salve.googlecode.com and live headache-free :)
-igor
On Wed, Oct 15, 2008 at 4:53 PM, Jeremy Thomerson <jeremy@wickettraining.com
> wrote:
> Try adding a constructor and putting this line in it:
>
> *InjectorHolder*.*getInjector*().*inject*(*this*);
>
> Works with Spring - haven't used Guice personally.
>
> --
> Jeremy Thomerson
> http://www.wickettraining.com
>
>
> On Wed, Oct 15, 2008 at 6:42 PM, Edgar Merino <do...@gmail.com> wrote:
>
> > Hello again,
> >
> > using guice's @Inject inside any component works perfect, however I've
> > got some objects (not components) that reside inside a component and need
> an
> > injected service, since wicket-guice handles only injection inside
> > components, I'm getting null services:
> >
> > public class Instantiator {
> > @Inject Service service;
> >
> > public Panel getPanel(String id) {
> > Author author = service.findAuthor("me");
> > return new SomePanel(id, author);
> > }
> > }
> >
> >
> > I need to fetch the "Author" outside the panel, the panel is not able to
> > fetch it. One approach might be to get the service from the Application,
> but
> > I do not want to do this since I don't want the application to know about
> my
> > Instantiator class, is there a better approach to accomplish what I need?
> > thanks in advance.
> >
> > Edgar Merino
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> > For additional commands, e-mail: users-help@wicket.apache.org
> >
> >
>
Re: Guice: injection outside Component
Posted by Edgar Merino <do...@gmail.com>.
Let me correct that last post, I forgot to add the @Inject annotation to
the service... it's working... thank you!
Edgar Merino
Edgar Merino escribió:
> Thank you Jeremy, I've tried that but it did not work:
>
> public class Instantiator {
> public Instantiator() {
> Injector injector = ( (GuiceInjectorHolder) CmsApplication.get()
>
> .getMetaData(GuiceInjectorHolder.INJECTOR_KEY)).getInjector();
>
> injector.injectMembers(this);
> }
>
> ...
> }
>
> maybe I'm doing something wrong? any other solution? thank you
>
> Edgar Merino
>
>
>
>
> Jeremy Thomerson escribió:
>> Try adding a constructor and putting this line in it:
>>
>> *InjectorHolder*.*getInjector*().*inject*(*this*);
>>
>> Works with Spring - haven't used Guice personally.
>>
>>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Guice: injection outside Component
Posted by Edgar Merino <do...@gmail.com>.
Thank you Jeremy, I've tried that but it did not work:
public class Instantiator {
public Instantiator() {
Injector injector = ( (GuiceInjectorHolder) CmsApplication.get()
.getMetaData(GuiceInjectorHolder.INJECTOR_KEY)).getInjector();
injector.injectMembers(this);
}
...
}
maybe I'm doing something wrong? any other solution? thank you
Edgar Merino
Jeremy Thomerson escribió:
> Try adding a constructor and putting this line in it:
>
> *InjectorHolder*.*getInjector*().*inject*(*this*);
>
> Works with Spring - haven't used Guice personally.
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org
Re: Guice: injection outside Component
Posted by Jeremy Thomerson <je...@wickettraining.com>.
Try adding a constructor and putting this line in it:
*InjectorHolder*.*getInjector*().*inject*(*this*);
Works with Spring - haven't used Guice personally.
--
Jeremy Thomerson
http://www.wickettraining.com
On Wed, Oct 15, 2008 at 6:42 PM, Edgar Merino <do...@gmail.com> wrote:
> Hello again,
>
> using guice's @Inject inside any component works perfect, however I've
> got some objects (not components) that reside inside a component and need an
> injected service, since wicket-guice handles only injection inside
> components, I'm getting null services:
>
> public class Instantiator {
> @Inject Service service;
>
> public Panel getPanel(String id) {
> Author author = service.findAuthor("me");
> return new SomePanel(id, author);
> }
> }
>
>
> I need to fetch the "Author" outside the panel, the panel is not able to
> fetch it. One approach might be to get the service from the Application, but
> I do not want to do this since I don't want the application to know about my
> Instantiator class, is there a better approach to accomplish what I need?
> thanks in advance.
>
> Edgar Merino
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>