Hi! First thing, amazing work with Hilt :wink: Jus...
# dagger
m
Hi! First thing, amazing work with Hilt 😉 Just two questions: • There are some situations in which you need to manually recreate the application dependencies graph and then inject the application again. Is there a way to do it with Hilt? ApplicationComponent is managed by the framework so it seems not. I mean, there’s a way to disable the automatic component creation and app injection in the @HiltAndroidApp and do it manually? • Let’s say I want to maintain the old dagger android way for the activities that I already have. How do I have to deal with AndroidSupportInjectionModule? It’s autogenerated so no way to add @InstallIn(ApplicationComponent::class) Side note: https://codelabs.developers.google.com/codelabs/android-dagger-to-hilt/index.html?index=..%2F..index#4 seems outdated
m
Regarding the migration, you can have the
AndroidSupportInjectionModule
included in a Hilt module
Copy code
@InstallIn(ApplicationComponent::class)
@Module(includes = [AndroidSupportInjectionModule::class]
interface DaggerAndroidModule {}
and then, to tell
dagger.android
to use Hilt’s ApplicationComponent, you can follow the guide here https://dagger.dev/hilt/migration-guide#daggerandroid-application
I’m curious about your first question. What’s your use case? Why would you want to do that?
m
thanks!! Need to do kind of in-app restart, and it requires to clean app and reinitialize the state of some dependencies
w
We also do the first one in UI tests. We don’t want to use Orchestrator as it slows them down a lot, but between tests we still want to reset as much of the application state as possible
m
For UI tests you don’t have to worry because you’ll get a fresh set of components for each test with
@HiltAndroidTest
and the
HiltAndroidRule
👌 2
For the in-app case, it’s not possible to reset the state of the
ApplicationComponent
. The
ApplicationComponentManager
holds a unique instance of it. I’d pay close attention to the
@Singleton
s of your app and reset state manually.
m
@Manuel Vivo I think creating a custom component and a scope, and then changing singleton to this new scope will allow me to recreate the graph.
Creating a custom component with application component as parent seemed to fix. But then when started migrating from dagger android to AndroidEntryPoint, android class injection fails because standard Hilt components don't see the custom component (as pointed out in the doc)
m
That’s because the rest of the Hilt components don’t have your custom component as a parent. It’s not possible to insert a custom component in the middle of the hierarchy
m
It would be a lot cooler if this was possible 😊
m
Is it in Hilt roadmap?
m
Unfortunately, it’s not at the moment. It’s technically very difficult to implement