我有一个看起来像这样的工厂:
public class Factory {
public Client createClient(String url) {
UrlBuilder urlBuilder = new UrlBuilder(url);
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpProcessor processor = new CompressionHttpProcessor();
httpClient.addRequestInterceptor(processor);
httpClient.addResponseInterceptor(processor);
return new Client(httpClient, urlBuilder);
}
}
像这样的一个类:
public class Facade {
private Factory factory;
private String url;
public Facade(Factory factory) {
this.factory = factory;
}
public void doStuff() {
Client client = factory.createClient(url);
// do stuff with client
}
public void setUrl(String url) {
this.url = url;
}
}
我如何正确使用 Google Guice 来做同样的事情?我尝试了辅助注射,但我不确定如何创建“UrlBuilder”。任何人都可以帮忙吗?