Mark Nuttall-Smith
unread,Sep 6, 2011, 4:46:28 PM9/6/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to google...@googlegroups.com
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