a best practice in Google Guice is to Inject Only Direct Dependencies.
But if I use the following example code, how could I create an instance of account in class Customer?
@Provides
Account providePurchasingAccount(Customer customer) {
return customer.getPurchasingAccount();
}
The problem is, that Guice always try to get a new Account by calling providePurchasingAccount(), which results in a circular references.
The method you excerpt is in the class CustomersModule, not Customer.
Here is more detail.
This depends on how Customer is bound.
In the Guice wiki page you mention it doesn’t show the binding for Customer.
Imagine the module also has this method.
In that case, when Account is injected first this method is called to get the Customer object then providePurchasingAccount is called to get the Account.