Sinan Gunes
02/15/2021, 12:43 PM@Assisted
parameter should return same object.wasyl
02/15/2021, 12:44 PMSinan Gunes
02/15/2021, 12:47 PMAssistedFactory
or hand made?wasyl
02/15/2021, 12:49 PMSinan Gunes
02/15/2021, 12:51 PMSinan Gunes
02/15/2021, 12:52 PMclass ChatRepositoryImpl @AssistedInject constructor(@Assisted("baseUrl") baseUrl: String)
: ChatRepository by buildRetrofit(baseUrl).create(ChatRepository::class.java) {
}
@AssistedFactory
interface ChatRepoFactory {
@Singleton
fun create(@Assisted("baseUrl") baseUrl: String): ChatRepositoryImpl
}
wasyl
02/15/2021, 12:53 PM@Singleton
is in wrong place — it should be placed at class ChatRepositoryImpl
, just like you would with a regular @Inject
Sinan Gunes
02/15/2021, 12:54 PM@Singleton
there, because it is not working. Also Dagger does not allow me to put above ChatRepositoryImpl
. :
Assisted Injection cannot be scoped
wasyl
02/15/2021, 12:56 PMwasyl
02/15/2021, 12:57 PMval instance1 = factory.create(baseUrl = "foo")
val instance2 = factory.create(baseUrl = "bar")
?Sinan Gunes
02/15/2021, 12:58 PMSinan Gunes
02/15/2021, 12:59 PMwasyl
02/15/2021, 1:04 PMI would expect to return different instances.If you want to return the same instances for the same `baseUrl`s then you just need to do that manually, Dagger won’t do that for you. So you’d need a
@Singleton
-scoped class which will internally hold ChatRepoFactory
and cache the returned instances for the same urlsSinan Gunes
02/15/2021, 1:09 PM