Matthew Madson
2016-12-02 21:42:18 UTC
Hi Guice Devs:
I assume this is a feature request but I was wondering if there was a way
to do something like the following:
interface Factory {
@Named("secure")
CloseableHttpClient createSecureClient();
@Named("insecure")
CloseableHttpClient createSecureClient();
}
class Module extends AbstractModule {
@Override
protected void configure() {
install(new FactoryModuleBuilder()
.implement(CloseableHttpClient.class, Names.named("secure"),
getProvider(Key.get(CloseableHttpClient.class, Names.named("secure"))))
.implement(CloseableHttpClient.class, Names.named("insecure"),
getProvider(Key.get(CloseableHttpClient.class, Names.named("insecure"))))
.build(Factory.class));
}
@Provides
@Named("secure")
CloseableHttpClient provideSecureHttpClient() {
return HttpClientBuilder.create()....build();
}
@Provides
@Named("insecure")
CloseableHttpClient provideInsecureHttpClient() {
return HttpClientBuilder.create().setSslcontext(SSLContexts.custom().
loadTrustMaterial(...).build()).build();
}
}
Basically I'd like to have the factory method bound to a provides method.
Best,
Matt
I assume this is a feature request but I was wondering if there was a way
to do something like the following:
interface Factory {
@Named("secure")
CloseableHttpClient createSecureClient();
@Named("insecure")
CloseableHttpClient createSecureClient();
}
class Module extends AbstractModule {
@Override
protected void configure() {
install(new FactoryModuleBuilder()
.implement(CloseableHttpClient.class, Names.named("secure"),
getProvider(Key.get(CloseableHttpClient.class, Names.named("secure"))))
.implement(CloseableHttpClient.class, Names.named("insecure"),
getProvider(Key.get(CloseableHttpClient.class, Names.named("insecure"))))
.build(Factory.class));
}
@Provides
@Named("secure")
CloseableHttpClient provideSecureHttpClient() {
return HttpClientBuilder.create()....build();
}
@Provides
@Named("insecure")
CloseableHttpClient provideInsecureHttpClient() {
return HttpClientBuilder.create().setSslcontext(SSLContexts.custom().
loadTrustMaterial(...).build()).build();
}
}
Basically I'd like to have the factory method bound to a provides method.
Best,
Matt
--
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/18619274-7912-438c-9ae7-e446632fb882%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-guice+***@googlegroups.com.
To post to this group, send email to google-***@googlegroups.com.
Visit this group at https://groups.google.com/group/google-guice.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-guice/18619274-7912-438c-9ae7-e446632fb882%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.