Just to make sure I understand...

Will this work? Even if the page and thus MyDataProvider gets serialized?

public MyDataProvider implements IDataProvider{

        @Inject MyDAO myDAO;

        public MyDataProvider() {
                InjectorHolder.getInjector().inject(this);
        }
}


On May 1, 2010, at 11:16 AM, Martin Grigorov wrote:

> public MyDataProvider() {
>    InjectorHolder.getInjector().inject(this);
> }
> 
> is the way in 1.4.8 which will be released these days.
> 
> Until then you'll have to use
> 
> public class MyInjector {
> 
>     public static void inject(Object target) {
>         GuiceInjectorHolder guiceInjectorHolder =
> Application.get().getMetaData(GuiceInjectorHolder.INJECTOR_KEY);
>        guiceInjectorHolder.getInjector().inject(target);
>     }
> }
> 
> i.e.: 
> public MyDataProvider() {
>    MyInjector.inject(this);
> }
> 
> On Sat, 2010-05-01 at 07:45 -0700, Douglas Ferguson wrote:
>> It there a good solution for using @Inject on non components,  i.e. a 
>> DataProvider.
>> 
>> For instance I have a DataProvider that does not use the default constructor 
>> so it cannot be injected into the page.
>> But the DataProvider will use a DAO and it would be nice to inject the DAO 
>> rather than having to pass the DAO from the page to the DataProvider.
>> 
>> I saw some examples of using an InjectionHolder, but from them example I 
>> saw, this seemed less than elegant, maybe the example was bad?
>> Also, I saw a post that mentioned something about using 
>> ComponentInstantiatioListener to do this?
>> 
>> D/
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
>> For additional commands, e-mail: users-h...@wicket.apache.org
>> 
>> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
> For additional commands, e-mail: users-h...@wicket.apache.org
> 


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

Reply via email to