Hi,
There are many ways to solve this problem, one easy enough to understand:
@Inject
Provider<CrawlerOne> crawlerOneProvider;
@Inject
Provider<CrawlerTwo> crawlerTwo;
public Crawler getCrawler(String url) {
if (url...) {
return crawlerOneProvider.get();
}
else {
return crawlerTwoProvider.get();
}
}
As an alternative you can inject the injector itself and get the instance from it.
Also a slightly more advanced, but much more elgant way is to use AssistedInject (it's exectly for this use case) See the guice docs for more info.
PS: no need to make everything static, the whole point of the DI framework that you don't need static anchors in your code.
--
L