diff --git a/misk/src/main/kotlin/misk/client/TypedHttpClientModule.kt b/misk/src/main/kotlin/misk/client/TypedHttpClientModule.kt index 087a8ddd15c..fb35e98017a 100644 --- a/misk/src/main/kotlin/misk/client/TypedHttpClientModule.kt +++ b/misk/src/main/kotlin/misk/client/TypedHttpClientModule.kt @@ -144,13 +144,15 @@ class TypedClientFactory @Inject constructor() { // Use Providers for the interceptors so Guice can properly detect cycles when apps inject // an HTTP Client in an Interceptor. // https://gist.github.com/ryanhall07/e3eac6d2d47b72a4c37bce87219d7ced - @Inject - private lateinit var clientNetworkInterceptorFactories: - Provider> + // Also, these are optional because the end user may not have used TypedHttpClientModule at all + // and thus may not have had multibindings provided here. + @Inject(optional = true) + private val clientNetworkInterceptorFactories: + Provider> = Provider { emptyList() } - @Inject - private lateinit var clientApplicationInterceptorFactories: - Provider> + @Inject(optional = true) + private val clientApplicationInterceptorFactories: + Provider> = Provider { emptyList() } @Inject private lateinit var clientMetricsInterceptorFactory: ClientMetricsInterceptor.Factory diff --git a/misk/src/test/kotlin/misk/client/TypedHttpClientTest.kt b/misk/src/test/kotlin/misk/client/TypedHttpClientTest.kt index cac00e9abfa..8b6d8538041 100644 --- a/misk/src/test/kotlin/misk/client/TypedHttpClientTest.kt +++ b/misk/src/test/kotlin/misk/client/TypedHttpClientTest.kt @@ -67,6 +67,18 @@ internal class TypedHttpClientTest { fun buildDynamicClients() { val typedClientFactory = clientInjector.getInstance(TypedClientFactory::class.java) + testBuildAndUseDynamicClient(typedClientFactory) + } + + @Test + fun buildDynamicClientWithoutHavingBuiltAnyOtherClients() { + val injector = Guice.createInjector(MiskTestingServiceModule()) + val typedClientFactory = injector.getInstance(TypedClientFactory::class.java) + + testBuildAndUseDynamicClient(typedClientFactory) + } + + private fun testBuildAndUseDynamicClient(typedClientFactory: TypedClientFactory) { val dinoClient = typedClientFactory.build( HttpClientEndpointConfig(jetty.httpServerUrl.toString()), "dynamicDino"