harry.singh
07/03/2020, 5:05 PMRetrofit
for my application, I'm using the Singleton
scope in my network module which is then included in the ApplicationComponent
with the same Singleton
scope. But in order to do that I've to add network dependencies to my app
module too. Is it possible to keep my retrofit instance singleton across application without adding network dependencies in my app module?Jovan
07/06/2020, 11:55 AMDaniel
07/10/2020, 6:46 PMChristian Maier
07/16/2020, 6:09 PMColton Idle
07/20/2020, 12:53 AMmiqbaldc
07/26/2020, 9:15 PMviewModelScope
?
Moved to this issue instead with more details and examples: https://github.com/google/dagger/issues/2004Colton Idle
07/29/2020, 5:53 PMKulwinder Singh
07/30/2020, 10:15 AMCallback
in Fragment using HILT
class PostAdapter @Inject constructor(
@ApplicationContext private val context: Context,
private val callback: Callback //HOW THIS CAN BE PROVIDED FROM FRAGMENT
) : ListAdapter<Post, PostAdapter.Holder>(DIFF) {
/.../
interface Callback {
fun onClick(post: Post)
}
}
Kulwinder Singh
07/30/2020, 10:23 AM@Inject PostAdapter
in any fragment ?Horv
07/30/2020, 11:41 AMtrevjones
07/30/2020, 3:38 PM@InstallIn
violating inversion of control? if not for the abstract concept of the monolithic component hierarchy creating a dependency inversion boundary it would be cyclic in nature 😕allan.conda
07/31/2020, 5:05 AMColton Idle
07/31/2020, 6:59 AM@Provides
)Jeevan Deep Singh
07/31/2020, 10:03 AMArchie
08/07/2020, 8:54 AMHilt
for Android DI. I am wondering whats the recommended approach of where to define the Hilt
Modules. In a multi-module project, is it ok to define Hilt
modules in each module? So for example I have a UserModule (Android Submodule)
and with in it I define the Hilt
Module. Or is it better to define all Hilt
Modules inside the app
Module itself?myanmarking
08/07/2020, 10:09 AMinterface Builder
class BuilderImpl @Inject(abstraction: Builder::class.java) constructor(): Builder
Marcin Środa
08/20/2020, 4:48 PM@AndroidEntryPoint
in case
package (com.android.ui.case
or something).
Result:
Failed Caused by: javassist.NotFoundException:
Are there any forbidden package names? (code without hilt annotation is working fine)Mohamed Ibrahim
08/24/2020, 3:20 PMArchie
08/25/2020, 12:11 PM@AndroidEntryPoint
class MyFragment: Fragment(), SomeInterfaceFromALibrary {
@Inject
lateinit var someClass: SomeClass
....
}
Now whenenver I build my project it says "could not access SomeInterfaceFromALibrary"
The only way I fixed it was to add the same dependency in the main module:
:app
...
dependencies {
implementation "someLibrary:version"
}
:otherModule
...
dependencies {
implementation "someLibrary:version"
}
Is this intended or am I doing something wrong?bodo
09/09/2020, 1:38 PMArchie
09/14/2020, 10:11 AM@ActivityRetainedScoped
but have a value injected to it from the Activity
. I need the depedency to survive device rotation but the problem is it also needs a value taken from the `Activity`'s bundle. Any advise on how to work around this?Ahmed Ibrahim
09/25/2020, 11:54 AMHiltAndroidTest
and they have UninstallModules
with the same set of modules to uninstall. If I add or remove an extra module to uninstall, I have to cascade the changes to the rest.
Is there a way to avoid repeating myself with Hilt or do I need to file a feature request for that?
What I tried and didn't work (inspired by Spring Boot TestComponent annotation)
@UninstallModules(SearchModule::class, SearchResultsModule::class, DestinationsSearchModule::class)
@HiltAndroidTest
internal class MonthsFragmentTest
Tried writing an annotation that combines them
@UninstallModules(
SearchModule::class,
SearchResultsModule::class,
DestinationsSearchModule::class
)
@kotlin.annotation.Target
annotation class UninstallSearchProductionModules
and tried replacing them
@UninstallSearchProductionModules
@HiltAndroidTest
internal class MonthsFragmentTest
Colton Idle
10/02/2020, 3:47 AMPete Doyle
10/08/2020, 3:04 AM@ContributesAndroidInjector
made it easy to have a module that is scoped to a specific Activity/Fragment, i.e.:
--- AppComponent:
@Singleton
@Component(
modules = [
ActivityBindingModule::class,
AndroidSupportInjectionModule::class,
// ...
]
)
interface AppComponent : AndroidInjector<MyApplication> {
// ...
}
--- ActivityBindingModule:
@Module
internal abstract class ActivityBindingModule {
@ActivityScope
@ContributesAndroidInjector(modules = [MainActivityModule::class]) // MainActivityModule scoped to MainActivity
internal abstract fun mainActivity(): MainActivity
@ActivityScope
@ContributesAndroidInjector(modules = [AnotherActivityModule::class]) // AnotherActivityModule scoped to AnotherActivity
internal abstract fun anotherActivity(): AnotherActivity
}
--- MainActivityModule:
@Module
abstract class MainActivityModule {
@FragmentScope
@ContributesAndroidInjector(modules = [SignInFragmentModule::class])
internal abstract fun signInFragment(): SignInFragment
@FragmentScope
@ContributesAndroidInjector
internal abstract fun whatsNewFragment(): WhatsNewFragment
@FragmentScope
@ContributesAndroidInjector
internal abstract fun settingsFragment(): SettingsFragment
}
Is something similar possible in HIlt? Or is there another strategy that might be similar? (random: if not, maybe in
It seems like MainActivityModule and AnotherActivityModule would both use @InstallIn(ActivityScoped::class)
, then both MainActivity and AnotherActivity could @Inject
from either (I might be missing something?).
Similarly, is it possible to have a setup where Fragments could @Inject
things from their host Activity’s module? (e.g. in the above example, SignInFragment could inject anything from AppComponent, MainActivityModule, and SignInFragmentModule.
We’ve taken advantage of this property of Dagger-Android, and I’m currently not quite sure what a migration to Hilt would look like.Bacho Kurtanidze
10/12/2020, 9:09 AMMiguel Coleto
10/13/2020, 7:03 PMclass UserDetailsViewModel(private val userId: String) : ViewModel() { ... }
With Koin I could inject it in my fragment/activity like this:
class UserDetailsFragment : Fragment() {
private val viewModel: UserDetailsViewModel by lifecycleScope.viewModel(parametersOf(
requireArguments().getString(USER_ID)
))
}
How can I achieve this with Dagger/Hilt?Shawn Witte
10/14/2020, 9:37 PM@Inject
on a Kotlin object
or are my only options to convert it to a class
or use @Provides
?Jeremy
10/21/2020, 1:44 AMjava.lang.reflect.InvocationTargetException (no error message)
. Is there any way to expand upon that to see what the actual issue is?pollux-
10/26/2020, 7:10 PMinterface DataMapper<T, R> {
fun transform(from: T): R
}
So I have couple of Data mapper in each use case layer .
Let's I have something like this
class AccountDataMapper @Inject constructor():
DataMapper<Account,Result<Account>>{
override fun transform(account : Account){
}
}
How can I bind this. I have many mapper in the like Login Mapper,User mapper.
When I use thr binder it's complaining that
@Binds method parameter type must be assignable to the return type
@Binds
abstract fun bindAccountMapper(mapper AccountDataMapper) : DataMapper<Account,Result<Account>>
Thanks in advanceblakelee
10/28/2020, 4:48 AMblakelee
10/28/2020, 4:48 AMallan.conda
10/28/2020, 7:10 AM@Binds
@IntoMap @ViewModelClassKey(LoginViewModel::class)
abstract fun bindViewModel(viewModel: SomeViewModel): ViewModel
Ahmed Ibrahim
10/28/2020, 9:46 AM@Inject
lateinit var viewModelProvider: Provider<MyViewModel>
private val myViewModel by viewModels {
viewModelProvider.get()
}
blakelee
10/29/2020, 1:41 AMallan.conda
10/29/2020, 1:41 AMblakelee
10/29/2020, 1:43 AMallan.conda
10/29/2020, 1:45 AM@ViewModelInject
otherwise there’s no easy way since ViewModels are a corner case,Ahmed Ibrahim
10/29/2020, 8:54 AM@Inject
lateinit var viewModelProvider: Provider<MyViewModel>
private val myViewModel: MyViewModel by viewModels {
object: ViewModelProvider.Factory {
override fun <T : ViewModel> create(modelClass: Class<T>): T {
@Suppress("UNCHECKED_CAST")
return viewModelProvider.get() as T
}
}
}
Now you can replace the ugly object: ViewModelProvider.Factory
part by extracting it to an inline function to get a much more elegant version of the above code
@Inject
lateinit var viewModelProvider: Provider<ViewModel>
private val myViewModel: ViewModel by viewModels {
createSimpleViewModelFactory { viewModelProvider.get()
}
}
blakelee
10/29/2020, 6:32 PM