galex
01/30/2024, 2:04 PMlaunchInHiltContainer
from the architecture-samples
with ViewModels that have an @AssistedFactory ?galex
02/05/2024, 4:58 AMDaniel Souza Bertoldi
02/11/2024, 3:18 PMBookStoreNotesApplication_HiltComponents.ViewModelC repeats modules with scoped bindings or declarations:
More details in thread!vide
03/11/2024, 3:11 PMBaseApplication
and when I remove the last injection, I get this when compiling tests:
Cannot process test roots and app roots in the same compilation unit:
App root in this compilation unit: vide.BaseApplication
Test roots in this compilation unit: [vide.Test1, vide.Test2, ...]
rkeazor
03/19/2024, 12:20 AMColton Idle
03/19/2024, 4:06 PM@Singleton
but, does that mean I have to add it to a module that it @InstallIn(SingletonComponent:class)?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 ActivityScope
kaeawc
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()
}