Eu configurei a injeção de dependências do meu projeto e estou recebendo um erro que não entendi muito bem e não achei em nenhum outro lugar.
Tenho dois arquivos AppModule.kt em módulos diferentes.
Este é o primeiro:
val viewModelModule = module {
viewModel { HomeViewModel(useCase = get()) }
}
Esse é o outro:
val apiServiceModule = module {
single<Retrofit> {
Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build()
}
single<ApiService> {
get<Retrofit>().create(ApiService::class.java)
}
}
val repositoryModule = module {
factory<GalleryRepository> {
GalleryRepositoryImpl(apiService = get())
} bind GalleryRepository::class
}
val useCaseModule = module {
factory<GalleryUseCase> {
GalleryUseCaseImpl(repository = get())
} bind GalleryUseCase::class
}
Estou recebendo este erro:
2021-12-01 18:58:05.634 29675-29675/? E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.luishenrique.cutecatsgallery, PID: 29675
java.lang.StackOverflowError: stack size 8MB
at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:944)
at org.koin.ext.KClassExtKt.getFullName(KClassExt.kt:25)
at org.koin.core.definition.BeanDefinitionKt.indexKey(BeanDefinition.kt:89)
at org.koin.core.registry.InstanceRegistry.resolveDefinition$koin_core(InstanceRegistry.kt:100)
at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:110)
at org.koin.core.scope.Scope.resolveValue(Scope.kt:254)
at org.koin.core.scope.Scope.resolveInstance(Scope.kt:241)
at org.koin.core.scope.Scope.get(Scope.kt:204)
at com.luishenrique.domain.di.AppModuleKt$useCaseModule$1$1.invoke(AppModule.kt:43)
at com.luishenrique.domain.di.AppModuleKt$useCaseModule$1$1.invoke(AppModule.kt:35)
at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:53)
at org.koin.core.instance.FactoryInstanceFactory.get(FactoryInstanceFactory.kt:38)
at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:110)
at org.koin.core.scope.Scope.resolveValue(Scope.kt:254)
at org.koin.core.scope.Scope.resolveInstance(Scope.kt:241)
at org.koin.core.scope.Scope.get(Scope.kt:204)
at com.luishenrique.domain.di.AppModuleKt$useCaseModule$1$1.invoke(AppModule.kt:43)
at com.luishenrique.domain.di.AppModuleKt$useCaseModule$1$1.invoke(AppModule.kt:35)
at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:53)
at org.koin.core.instance.FactoryInstanceFactory.get(FactoryInstanceFactory.kt:38)
at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:110)
at org.koin.core.scope.Scope.resolveValue(Scope.kt:254)
at org.koin.core.scope.Scope.resolveInstance(Scope.kt:241)
at org.koin.core.scope.Scope.get(Scope.kt:204)
at com.luishenrique.domain.di.AppModuleKt$useCaseModule$1$1.invoke(AppModule.kt:43)
at com.luishenrique.domain.di.AppModuleKt$useCaseModule$1$1.invoke(AppModule.kt:35)
at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:53)
at org.koin.core.instance.FactoryInstanceFactory.get(FactoryInstanceFactory.kt:38)
at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:110)
at org.koin.core.scope.Scope.resolveValue(Scope.kt:254)
at org.koin.core.scope.Scope.resolveInstance(Scope.kt:241)
at org.koin.core.scope.Scope.get(Scope.kt:204)
at com.luishenrique.domain.di.AppModuleKt$useCaseModule$1$1.invoke(AppModule.kt:43)
at com.luishenrique.domain.di.AppModuleKt$useCaseModule$1$1.invoke(AppModule.kt:35)
at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:53)
at org.koin.core.instance.FactoryInstanceFactory.get(FactoryInstanceFactory.kt:38)
at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:110)
at org.koin.core.scope.Scope.resolveValue(Scope.kt:254)
at org.koin.core.scope.Scope.resolveInstance(Scope.kt:241)
at org.koin.core.scope.Scope.get(Scope.kt:204)
at com.luishenrique.domain.di.AppModuleKt$useCaseModule$1$1.invoke(AppModule.kt:43)
at com.luishenrique.domain.di.AppModuleKt$useCaseModule$1$1.invoke(AppModule.kt:35)
at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:53)
at org.koin.core.instance.FactoryInstanceFactory.get(FactoryInstanceFactory.kt:38)
at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:110)
at org.koin.core.scope.Scope.resolveValue(Scope.kt:254)
at org.koin.core.scope.Scope.resolveInstance(Scope.kt:241)
at org.koin.core.scope.Scope.get(Scope.kt:204)
at com.luishenrique.domain.di.AppModuleKt$useCaseModule$1$1.invoke(AppModule.kt:43)
at com.luishenrique.domain.di.AppModuleKt$useCaseModule$1$1.invoke(AppModule.kt:35)
at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:53)
at org.koin.core.instance.FactoryInstanceFactory.get(FactoryInstanceFactory.kt:38)
2021-12-01 18:58:07.283 29675-29675/? E/AndroidRuntime: at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:53)
at org.koin.core.instance.FactoryInstanceFactory.get(FactoryInstanceFactory.kt:38)
at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:110)
at org.koin.core.scope.Scope.resolveValue(Scope.kt:254)
at org.koin.core.scope.Scope.resolveInstance(Scope.kt:241)
at org.koin.core.scope.Scope.get(Scope.kt:204)
at com.luishenrique.cutecatsgallery.di.AppModuleKt$viewModelModule$1$1.invoke(AppModule.kt:14)
at com.luishenrique.cutecatsgallery.di.AppModuleKt$viewModelModule$1$1.invoke(AppModule.kt:8)
at org.koin.core.instance.InstanceFactory.create(InstanceFactory.kt:53)
at org.koin.core.instance.FactoryInstanceFactory.get(FactoryInstanceFactory.kt:38)
at org.koin.core.registry.InstanceRegistry.resolveInstance$koin_core(InstanceRegistry.kt:110)
at org.koin.core.scope.Scope.resolveValue(Scope.kt:254)
at org.koin.core.scope.Scope.resolveInstance(Scope.kt:241)
at org.koin.core.scope.Scope.get(Scope.kt:204)
at androidx.lifecycle.StateViewModelFactory.create(StateViewModelFactory.kt:17)
at androidx.lifecycle.AbstractSavedStateViewModelFactory.create(AbstractSavedStateViewModelFactory.java:69)
at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:185)
at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150)
at org.koin.androidx.viewmodel.ViewModelResolverKt.resolveInstance(ViewModelResolver.kt:15)
at org.koin.androidx.viewmodel.scope.ScopeExtKt.getViewModel(ScopeExt.kt:67)
at org.koin.androidx.viewmodel.scope.ScopeExtKt.getViewModel(ScopeExt.kt:53)
at org.koin.androidx.viewmodel.scope.ScopeExtKt.getViewModel$default(ScopeExt.kt:45)
at org.koin.androidx.viewmodel.ext.android.ComponentCallbackExtKt.getViewModel(ComponentCallbackExt.kt:63)
at com.luishenrique.cutecatsgallery.ui.view.HomeActivity$special$$inlined$viewModel$default$2.invoke(ComponentCallbackExt.kt:65)
at com.luishenrique.cutecatsgallery.ui.view.HomeActivity$special$$inlined$viewModel$default$2.invoke(ComponentCallbackExt.kt:42)
at kotlin.UnsafeLazyImpl.getValue(Lazy.kt:81)
at com.luishenrique.cutecatsgallery.ui.view.HomeActivity.getMViewModel(HomeActivity.kt:15)
at com.luishenrique.cutecatsgallery.ui.view.HomeActivity.onCreate(HomeActivity.kt:23)
at android.app.Activity.performCreate(Activity.java:7009)
at android.app.Activity.performCreate(Activity.java:7000)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1214)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2742)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2872)
at android.app.ActivityThread.-wrap11(Unknown Source:0)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1595)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6543)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:810)