>
> That's my preferred way to do injection in services and it avoids problems
> like you're having

If you do that, you'll have to refactor your constructor parameters and
assignment statement if you remove\add a new service. It should be a lot
easier to use

@Inject
private MyService svc;

If using a constructor makes sure that all passed services (as parameters
to the constructor) are proxied and ready to be instantiated, then so
should injecting a service as a class member (i.e. as the 2 lines of code I
wrote earlier), they should behave the same, else it would be a bug,
exactly like you said.

The only case I know where one MUST use a service's constructor to pass a
dependency, is when you need the logger service injected.

*---------------------*
*Muhammad Gelbana*
http://www.linkedin.com/in/mgelbana


On Fri, Nov 22, 2013 at 7:55 PM, Dmitry Gusev <dmitry.gu...@gmail.com>wrote:

> @EagerLoad is for service builder methods:
>
> http://tapestry.apache.org/5.3.7/apidocs/org/apache/tapestry5/ioc/annotations/EagerLoad.html
>
> Don't use TimeTask, use Tapestry's PeriodicExecutor with
>
> http://tapestry.apache.org/current/apidocs/org/apache/tapestry5/ioc/annotations/Startup.html
>
>
>
>
> On Fri, Nov 22, 2013 at 9:47 PM, John <j...@quivinco.com> wrote:
>
> > I need my setup method to run when this class is instantiated but log is
> > null so mailDAO will also be null.
> >
> > John
> >
> >
> > public class EmailReceiverUtil {
> >
> >     public static final int SHOW_MESSAGES = 1;
> >     public static final int CLEAR_MESSAGES = 2;
> >     public static final int SHOW_AND_CLEAR =
> >             SHOW_MESSAGES + CLEAR_MESSAGES;
> >     /**
> >      * The log.
> >      */
> >     @Inject
> >     private Logger log;
> >     @Inject
> >     private MailDAO mailDAO;
> >     /**
> >      * Mail properties
> >      */
> >     Properties props = new Properties();
> >     /**
> >      * Timer for background task;
> >      */
> >     Timer timer = new Timer();
> >
> >     public EmailReceiverUtil() {
> >         System.out.println("EmailReceiverUtil instantiated");
> >     }
> >
> >     @EagerLoad
> >     public void setup() {
> >         // configure properties
> >         props.put("mail.user", "John");
> >         props.put("mail.host", "diskstation");
> >         props.put("mail.debug", "false");
> >         props.put("mail.store.protocol", "pop3");
> >         timer.schedule(new MailReceiverThread(), 1000, 60000);
> >         log.info("Email Receiver running");
> >     }
> >
> >     private void checkInbox(int mode)
> >         ...
> >     }
> >
> >     private boolean processPlainTextMessage(final String from, final
> > String to,
> >             final String subject, final String message) {
> >         try {
> >             String messageText = message;
> >             return mailDAO.processIncomingMail(from, to, messageText);
> >         } catch (DAOException ex) {
> >             ex.printStackTrace();
> >         }
> >         return false;
> >     }
> >
> >     class MailReceiverThread extends TimerTask {
> >
> >         public void run() {
> >             try {
> >                 checkInbox(CLEAR_MESSAGES);
> >             } catch (Exception ex) {
> >                 ex.printStackTrace();
> >             }
> >         }
> >     }
> > }
> >
> >   ----- Original Message -----
> >   From: Thiago H de Paula Figueiredo
> >   To: Tapestry users
> >   Sent: Friday, November 22, 2013 5:26 PM
> >   Subject: Re: Tapetsry IoC starting a class with background task that
> > uses an injected service
> >
> >
> >   On Fri, 22 Nov 2013 14:03:10 -0200, John <j...@quivinco.com> wrote:
> >
> >   > How do I get this class to load when I start my app and make sure the
> >   > injected services are set? With EagerLoad the class gets instantiated
> >   > but of course the services are null.
> >
> >   This statement is not correct as far as I know. Tapestry-IoC injects
> >   service proxies (when the service is defined by an interface), so the
> >   dependencies may not even be initialized yet, but, when you first call
> >   them, they will be initialized.
> >
> >   --
> >   Thiago H. de Paula Figueiredo
> >   Tapestry, Java and Hibernate consultant and developer
> >   http://machina.com.br
> >
> >   ---------------------------------------------------------------------
> >   To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org
> >   For additional commands, e-mail: users-h...@tapestry.apache.org
> >
>
>
>
> --
> Dmitry Gusev
>
> AnjLab Team
> http://anjlab.com
>

Reply via email to