You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Foror <fo...@mail.ru> on 2008/04/09 06:08:07 UTC

get perthread_scope service from singleton_scope service

// singleton
public IChatCoordinator buildChatCoordinator() {...}

@Scope(IOCConstants.PERTHREAD_SCOPE)
public IPerthredService buildPerthreadService(@Inject IOtherPerthredService) {...}

---

// singleton
public class ChatCoordinator implements IChatCoordinator {

    // for every call this method needed new IPerthredService
    public void someMethod() {
       IPerthredService service = ? // who build new IPerthredService?
    }
}

public class ChatJobSchedule extends TimerTask {

  private IChatCoordinator op;

  public ChatJobSchedule(IChatCoordinator op) {
    this.op = op;
  }

  @Override
  public void run() {
    op.someMethod();
  }
}


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


Re: get perthread_scope service from singleton_scope service

Posted by Howard Lewis Ship <hl...@gmail.com>.
Well, if you inject a perthread-scoped service into a normal
(singleton) service, you'll get the proxy.  Invoking methods on the
proxy will create the per-thread instance "behind the scenes", which
may be what you want.

On the other hand, you may be using something I tend to call a
"process object", an object that holds state and is passed around to a
number of stateless services.  In that case, you may want to follow
Kristian's advice and define a factory service that creates the
process object (thus hiding its internal structure, including any
injected dependencies).  And, of course, the process object should be
defined in terms of an interface.  This pattern is all over Tapestry.

On Tue, Apr 8, 2008 at 9:08 PM, Foror <fo...@mail.ru> wrote:
> // singleton
>  public IChatCoordinator buildChatCoordinator() {...}
>
>  @Scope(IOCConstants.PERTHREAD_SCOPE)
>  public IPerthredService buildPerthreadService(@Inject IOtherPerthredService) {...}
>
>  ---
>
>  // singleton
>  public class ChatCoordinator implements IChatCoordinator {
>
>     // for every call this method needed new IPerthredService
>     public void someMethod() {
>        IPerthredService service = ? // who build new IPerthredService?
>     }
>  }
>
>  public class ChatJobSchedule extends TimerTask {
>
>   private IChatCoordinator op;
>
>   public ChatJobSchedule(IChatCoordinator op) {
>     this.op = op;
>   }
>
>   @Override
>   public void run() {
>     op.someMethod();
>   }
>  }
>
>
>  ---------------------------------------------------------------------
>  To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>  For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

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


Antwort: get perthread_scope service from singleton_scope service

Posted by Kristian Marinkovic <kr...@porsche.co.at>.
pass in a factory service to your ChatCoordinator that will 
return a new instance on every invocation (eg. create(....))

g
kris



Foror <fo...@mail.ru> 
09.04.2008 06:08
Bitte antworten an
"Tapestry users" <us...@tapestry.apache.org>


An
Tapestry users <us...@tapestry.apache.org>
Kopie

Thema
get perthread_scope service from singleton_scope service







// singleton
public IChatCoordinator buildChatCoordinator() {...}

@Scope(IOCConstants.PERTHREAD_SCOPE)
public IPerthredService buildPerthreadService(@Inject 
IOtherPerthredService) {...}

---

// singleton
public class ChatCoordinator implements IChatCoordinator {

    // for every call this method needed new IPerthredService
    public void someMethod() {
       IPerthredService service = ? // who build new IPerthredService?
    }
}

public class ChatJobSchedule extends TimerTask {

  private IChatCoordinator op;

  public ChatJobSchedule(IChatCoordinator op) {
    this.op = op;
  }

  @Override
  public void run() {
    op.someMethod();
  }
}


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