Hi,

I have an class with a parameterized constructor using AssistedInject as 
follows:

  @Inject
  Portfolio (QuoteDao dao, @Assisted Params params) {...}

I create an instance of this class in a command handling servlet:

  public class Handler {
    @Inject Strategy strategy;
    Result execute(Action action) {
      Portfolio portfolio = portfolioFactory.create(action.params);
      strategy.execute();
    }
  }
  
My uncertainty begins when I need to obtain a reference to the portfolio in 
other components of the system. Ideally I'd have it included as part of the 
constructor, but since it isn't available at injection time this isn't 
possible. 

  public class Strategy {
    Portfolio portfolio; <-- how should I get this here?
    @Inject
    public Strategy(QuoteDao dao, ??) {...}
    public execute();
  }

The example is somewhat simplified - it's not possible to simply pass the 
portfolio as part of the execute() call.
  
I've thought through various solutions, but none seem ideal:
    * Inject a PortfolioProvider - but how does the provider get access to 
the portfolio?
    * Save the portfolio in the Handler against the logged in user (I'm 
using appengine), then use the logged in user to retrieve in a provider - 
but I would like the system to be able to handle anonymous users
    * Store the portfolio in a static ThreadLocal, access in a provider 
again - seems very clunky
    
Would appreciate it very much if someone could help me out here? I'm a 
newbie with Guice, so hopefully I'm missing something obvious...

Thanks,
Mark

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/google-guice/-/xuNJJV0EeDoJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-guice?hl=en.

Reply via email to