如何使用Guice的AssistedInject?
我已经阅读了https://github.com/google/guice/wiki/AssistedInject ,但是没有说明如何传入AssistedInject参数的值。 injector.getInstance()调用会是什么样子?
检查FactoryModuleBuilder类的javadoc。
 AssistedInject允许您dynamicconfigurationFactory ,而不是自己编写。 当你有一个应该被注入的依赖关系的对象和在创build对象时必须被指定的一些参数时,这通常是有用的。 
来自docummentaiton的例子是一个RealPayment
 public class RealPayment implements Payment { @Inject public RealPayment( CreditService creditService, AuthService authService, @Assisted Date startDate, @Assisted Money amount) { ... } } 
 请参阅CreditService和AuthService应该由容器注入,但startDate和金额应该在创build实例期间由开发人员指定。 
 所以,而不是注入一个Payment你注入一个PaymentFactory的参数标记为@Assisted在RealPayment 
 public interface PaymentFactory { Payment create(Date startDate, Money amount); } 
工厂应该被绑住
 install(new FactoryModuleBuilder() .implement(Payment.class, RealPayment.class) .build(PaymentFactory.class)); 
configuration的工厂可以注入你的课程。
 @Inject PaymentFactory paymentFactory; 
并在你的代码中使用
 Payment payment = paymentFactory.create(today, price);