mattinger
10/20/2022, 11:06 PMinterface SomeTypeFactory: Function0<SomeType>
And use that instead, i get the same sort of errorjw
10/20/2022, 11:07 PMjw
10/20/2022, 11:07 PMjw
10/20/2022, 11:08 PMmattinger
10/20/2022, 11:12 PMmattinger
10/20/2022, 11:13 PMfactories: Map<@JvmSuppressWildards Class<*>, @JvmSuppressWildards () -> SomeType>
mattinger
10/20/2022, 11:14 PMagrosner
10/21/2022, 2:15 AMSushobh
11/01/2022, 2:48 AMSergio C.
11/01/2022, 11:11 PM@Module
@InstallIn(SingletonComponent::class)
class ApiModule @Inject constructor(
localPrefs: SharedPreferences,
app: Application,
) {
init {
localPrefs.registerOnSharedPreferenceChangeListener { prefs: SharedPreferences?, key: String? ->
if (key == app.getString(R.string.pref_key_api_url)) {
val newApiUrl = prefs?.getString(key, defaultApiUrl) ?: defaultApiUrl
Logger.w("API URL CHANGED!!! $newApiUrl")
}
}
}
}Preetham Ivan Dsouza
11/07/2022, 12:35 PMcertificatePinner
etc (if we are setting keys dynamically and not locally) how do we achieve the same with Hilt?
Ref: Similar use case to this issueKshitij Patil
11/28/2022, 6:47 AMFooImpl
for an interface Foo
when annotated. Now I want dagger to know binding Foo
with FooImpl
from my generated code. Adding simple @Inject
to the constructor of generated class doesn’t work, I guess because the code is not available at compile time. How can I achieve this?Christoph Wiesner
12/14/2022, 7:12 AM@Provides
fun provideManager(config, managerImplA, managerImplB): Manager {
return if (config.shouldUseA) {
managerImplA
} else {
managerImplB
}
}
doing this means i have to instantiate both implementation but only one gets used in the end.
problem is that all the dependencies of the implementation also will get wired up and kick off some processes that i do not want to be instantiated if that version is not gonna be used.
is there a way to achieve this without having the instances already?dimsuz
12/16/2022, 11:37 AMinterface A
interface B
class AB : A, B
And I want to have a single intance of AB
provided as A
and B
separately:
@Provides fun providesA(): A
@Provides fun providesB(): B
How is this normally done in dagger? Do I do it like this:
@Provides fun providesAB(): AB
@Provides fun providesA(ab: AB): A = ab
@Provides fun providesB(ab: AB): B = ab
Feels like there could be a way to avoid manually writing such basic methods.
Also don't like the fact that I have to provide AB
too, although I'd prefer it to be an implemenation detailnuhkoca
12/27/2022, 2:46 PMbenchmark
module throws the exception below when executing ./gradlew connectedBenchmarkAndroidTest -Pandroid.testInstrumentationRunnerArguments.androidx.benchmark.enabledRules=BaselineProfile
task
symbol: class DeveloperSettingsModule
error: ComponentProcessingStep was unable to process 'path.to.package.core.di.ApplicationComponent' because '<error>' could not be resolved.
Can somebody please help me figure out what’s wrong with Dagger? I am confused.mattinger
01/13/2023, 1:52 PMjw
01/13/2023, 1:54 PMjw
01/13/2023, 1:54 PMmattinger
01/13/2023, 1:57 PMEmirhan Emmez
01/18/2023, 7:39 PMSusheel
01/19/2023, 5:24 PMConstantin Cezar Begu
01/23/2023, 3:30 PMColton Idle
01/27/2023, 7:26 AMclass GetTeamsUseCase @Inject constructor(
val apiService: ApiService, <---- provided by a @Provides method
val accessToken: String <---- I'd like to "inject" this at runtime since I get it once I login
) {
Is this possible to do or do I need some other lirbary?Philip Dukhov
02/06/2023, 2:53 PMActivityScoped
, when activity is destroyed - in this particular case I could've get an activity with ActivityContext
and listen to the lifecycle, but this won't work generally, e.g. with ActivityRetainedScoped
.
The only idea that come to my mind is using finalize
but it seems to be a bad practice and doesn't seems to be reliable - as I understand there's no guarantee it'll be called on time.
Usually Closeable
is used in such situations, I've tried implementing it but Dagger doesn't seems to be checking it.Colton Idle
02/08/2023, 7:20 PMapp
gradle module which depends on service
. And service
inside has SomeServiceClass
. Would service
gradle module have a @Module and @Provides, providing the SomeServiceClass
to app
gradle module? Or is it more customary for the service
gradle module to declare what it provides?Colton Idle
02/09/2023, 10:20 PMColton Idle
02/10/2023, 4:15 PM:app
module and then a network
module. I want the network module to expose services like BooksService and LibraryService. Those two services require a OkHttpClient. I can also add a provider for the http client, but then okhttpClient provider is exposed to the app.
Anyway to hide that "internal" dependency with dagger?
networkModule's provider declaration:
@Provides
fun provideBooksService(okHttpClient: OkHttpClient): BooksService {
return NetworkBackedBooksService(okHttpClient)
}
@Provides
fun provideLibraryService(okHttpClient: OkHttpClient): LibraryService {
return NetworkBackedLibraryService(okHttpClient)
}
@Provides
fun providesHttpClient(): OkHttpClient {
return //...
}
Dave Scheck
02/14/2023, 9:29 PMAssisted Injection
to pass runtime parameters into objects being injected. What I haven't been able to figure out is how to use that (or another mechanism) to choose the type of object being injected based on a runtime parameter. For example, without using DI I might do something like this
class RepoDataSourceScreenViewModel: ViewModel() {
var isSimulated = lookupIsSimulated()
val repository = ComponentRepository(isSimulated)
// This would be backed by a DB/sharedPref lookup
private fun lookupIsSimulated(): Boolean = false
}
class ComponentRepository(val isSimulated: Boolean) {
val dataSource = if(isSimulated) RealComponentDataSource() else SimComponentDataSource()
}
abstract class ComponentDataSource()
class RealComponentDataSource() {}
class SimComponentDataSource() {}
Is there an equivalent be in a Dagger/Hilt environment?ursus
02/19/2023, 2:26 AMColton Idle
02/23/2023, 10:20 PM