ursus
03/27/2024, 11:33 PMComponentsCache which holds Component instances (currently just a flat list of Any)
I use hierarchies of components, i.e. subcomponents.
When I delete component X from the cache, I want to remove it's children automatically as well.
Therefore I need a parent-child relationship between the components.
I could handle all this myself, i.e. have some sort of CacheNode(component, parentCacheNode) etc.
However, I do know child components do have a parent component reference.
Is this accessible from outside somehow? (So I avoid having a multiple sources of truth)rkeazor
04/02/2024, 11:19 PMrkeazor
04/07/2024, 3:28 PMAbdullah Musa
04/18/2024, 8:13 AMCarl Benson
04/25/2024, 6:52 AM@LazyClassKey annotation and having a custom @MapKey and accessing that map with Map<Class<out Foo>, @JvmSuppressWildcards Provider<Foo>>Jeevan Deep Singh
04/27/2024, 9:14 PMunable to resolve even though the files get successfully generated. I am assuming it because of some order issue. is it possible to change the order of annotation processing so that my code generated by KSP always runs first and dagger's(kapt) runs after?Marco Righini
04/30/2024, 4:25 PM@HiltAndroidApp
class LogApplication : Application() {
@Inject
internal lateinit var dependency: LoggerInMemoryDataSource
override fun onCreate() {
super.onCreate()
logout()
}
@Suppress("CAST_NEVER_SUCCEEDS")
private fun regenerateComponent() {
Log.d("", "Before: $dependency")
val cm = (this as GeneratedComponentManagerHolder).componentManager()
val f = ApplicationComponentManager::class.java.declaredFields.find { it.name == "component" }
f?.let {
it.isAccessible = true
f.set(cm, null)
}
((this as GeneratedComponentManager<ApplicationComponentManager>)
.generatedComponent() as LogApplication_GeneratedInjector)
.injectLogApplication(UnsafeCasts.unsafeCast(this))
Log.d("", "After: $dependency")
}
fun logout() {
regenerateComponent()
}
}
(LoggerInMemoryDataSource is a singleton and the reference is changing)
Do you foresee any drawback apart of the need of testing on every Hilt upgrade?
Should we propose to support this use case in Hilt?
Thanks!Brais Gabin
05/10/2024, 9:40 AMursus
05/10/2024, 12:27 PMColton Idle
05/16/2024, 12:52 PM@ActivityContext private val activityContext: Context but I get a compile time error about Context not being provided. Is this use case of using two qualified contexts, not supported for some reason? or is Hilt bugging out on meNick Kleban
05/20/2024, 2:14 PMColton Idle
05/24/2024, 5:01 PM@Module
@InstallIn(SingletonComponent)
interface MyModule {
companion object {
@Provides
@Singleton
fun provideThing(builder: MyBuilder): Thing = builder.build()
}
}
I'm not sure of the reason why this is an interface with a companion object. Can someone explain why?
Additionally... if I wanted to add a new provides method for a simple Foo object would I just do
@Provides
fun provideFoo() = Foo()
inside of the companion object, or outside of the companion?ursus
06/10/2024, 8:42 AMaComponentImpl reference. Is there a way to get it from outside? (i.e. to figure out who the parent of bComponent instance is?). Or do I need to track this myself (although not a single source of truth)galex
06/15/2024, 7:34 AMinitFiler doesn't exist anymore, so I guess I have to go get processingEnv?.ksp()?.codeGenerator instead? Some examples would be welcomed 😊galex
06/17/2024, 4:31 AMdagger-spi is there a way to modify the binding graph ?
I've generated dagger modules for missing bindings and I'd like to add those modules (or components?) to the bindingGraph 🤔ursus
07/11/2024, 12:01 PMApp -> User
|_-> RegistrationFlow
i..e user na registration are children of app, but don't see each other.
There is a dependency Foo that only needs dependencies from App component, so it's injectable in bot User and RegFlow , however I want to cache it per child scope. i.e instance1 in User and instance2 in RegistrationFlow as it is stateful.
Is this possible? Other than not having @Inject on Foo and having 2 module @Provides functions
Basically I want
@User
@RegistarationFlow
class Foo @Inject constructor(..)
but compiler complainslam bui
09/20/2024, 7:23 AMprudhvi reddy
09/23/2024, 5:18 PMEarlyEntryPoints is not possible
As Worker class dependencies uses a different graph of objects and doesn't share any state with Singleton graph
Any workarounds to test cases like this?
https://dagger.dev/hilt/early-entry-pointColton Idle
09/25/2024, 1:23 AMDevanshu Pathsariya
10/01/2024, 9:34 AMA has an interface(SampleInterface) whose implementation is requested in the Activity,
Module app provides the implementation of the SampleInterface and binds it.
How is lower level module's activity is injected with the Implementation from the higher level module
FYI: SampleInterface is bound to the ActivityScopekaeawc
10/14/2024, 3:13 AMAbdullah Musa
11/07/2024, 9:48 AMTTSProvider instance. I would like to check whether it has been initialized when cleaning up. Is there a better/prettier solution than my current one?
@Provides
fun provideLazyTTSProvider(
ttsProvider: dagger.Lazy<TTSProvider>,
): kotlin.Lazy<TTSProvider> {
return kotlin.lazy { ttsProvider.get() }
}ursus
01/25/2025, 1:15 AMalexhelder
04/09/2025, 3:06 AMDeferred<T> from @Provides, like this:
@Provides
@Singleton
fun provideAppConfig(
coroutineScope: CoroutineScope
): Deferred<AppConfigValues> =
coroutineScope.async {
... some suspend functions ...
AppConfigValues()
}Marek Kubiczek
06/03/2025, 6:40 AMColton Idle
07/02/2025, 12:15 PMColton Idle
07/30/2025, 5:36 PM@Singleton
class Foo @Inject constructor(private val bar: Bar)
...
and it's also defined in a @module @installIn(SingletonComponent)
as
@Provides
@Singleton
fun provideFoo(bar: Bar){
return Foo(bar)
}
that's "bad", right? Or is it just duplicative and not necessarily bad?
Isn't the whole point for @Provides is to provide creation of classes that you dont own?HyeonBae Ji
07/31/2025, 2:29 PMKaran Sharma
10/17/2025, 3:17 AMMaksym M.
10/21/2025, 12:53 PMprivate val providers: Map<Class<out Fragment>, @JvmSuppressWildcards Provider<Fragment>>
I generate Hilt modules with ksp and these look like this
@Module
@InstallIn(SingletonComponent::class)
public object HiltNavigationAlertDialogModule {
@Provides
@IntoMap
@NavigationEntryMap
@LazyClassKey(AlertDialog::class)
public fun bindAlertDialog(): Fragment = AlertDialog()
}
I see that hilt aggregares the dependency but fails to inject it at the injection site I posted above
Is there some tampering with types I need to do? The errors are of no use and I am out of ideas