我已经创建了一个抽象的BaseFragment类,它将被其他具体的Fragment类扩展。我想使用Koin在我的BaseFragment中注入(inject)ViewModel。这是我的BaseFragment:abstractclassBaseFragment(privatevalmViewModelClass:Class):Fragment(){valviewModel:VMbyviewModel()openlateinitvarbinding:DBfuninit(inflater:LayoutInflater,container:ViewGroup){binding=DataBi
我想为koin编写测试。我使用RoomDatabase,它在构造函数中接收上下文。应用运行良好但测试失败Can'tresolveApplicationinstance.PleaseuseandroidContext()functioninyourKoinApplicationconfiguration. 最佳答案 如果你想在你的模块中使用上下文,你应该在你的startkoin方法中传递上下文//startKoin!startKoin{//declareusedAndroidcontextandroidContext(this@MyA
我有2个改造客户端,其中一个是默认的,第二个有不同的实现,例如(基本URL、拦截器等...)我需要在不使用名称引用的情况下注入(inject)默认客户端第一个客户:-single{Retrofit.Builder().baseUrl(RemoteConstants.BASE_URL).addCallAdapterFactory(RxJava2CallAdapterFactory.create()).addConverterFactory(APIResponseConverter()).addConverterFactory(GsonConverterFactory.create(get
我正在尝试使用Koin创建用户范围。当用户登录时,我正在创建范围:valscope=getKoin().createScope("USER_SCOPE")当用户点击注销时,我正在破坏作用域scope?.let{userScope->userScope.close()getKoin().deleteScope(userScope.id)}在我的koin模块中,我有一个scopedUserRepository,它应该只在用户session期间存在。我还有使用此存储库的ViewModel和用例,我尝试在其中注入(inject)scopedrepovalappModule=module{sco
我正在开发一个基于KoinDI(版本:1.0.1)的应用程序,有2个模块(:应用程序和:网络)。我在:network模块中要求有“上下文”。以下是我的实现方式:**Module**:valappModule=module{viewModel{LoginViewModel(get())}}**Activity**:privatevalviewModelbyviewModel()**ViewModel**:classLoginViewModel(valcontext:Context):ViewModel(){...//Send"context"tonetworkclassin:networ
收到消息错误java.lang.RuntimeException:Unabletocreateapplicationcom.app.name.application.MainApplication:org.koin.error.BeanInstanceCreationException:Can'tcreatebeanBean[class=com.app.name.general.preferences.Preferences]duetoerror:org.koin.error.NoBeanDefFoundException:Nodefinitionfoundtoresolvetype'
当我将Koin添加到项目中时,我不断遇到以下错误。StandAloneContextKoin实例为空实现'org.koin:koin-android:1.0.2'Modules.ktvalUIModule:Module=module{factory{MainPresenter()}}valappModules=listOf(UIModule)App.ktclassApp:Application(){privatevalTAG:String=Application::class.java.nameoverridefunonCreate(){super.onCreate()startKoi
我有一个Activity应用程序。我想将viewModel绑定(bind)到父fragment生命周期(FlowFragmentLogin),并与子fragment(CellFragment、InfoFragment、等)。因此,当我从FlowFragmentLogin移动到FlowFragmentMain时,调用了viewModelonCleared()。但我发现的唯一方法是在Activity及其Fragment之间共享viewModel:https://insert-koin.io/docs/1.0/documentation/koin-android/index.html并且无法
我有像这样的顶级功能funsendNotification(context:Context,data:Data){...//alotofcodehere}该功能创建通知,有时通知可以包含图像,所以我必须下载它。我正在使用包裹在接口(interface)ImageManager上的Glide,所以我必须注入(inject)它。我使用Koin进行DI,问题是我不会写valimageManager:ImageManagerbyinject()在我的代码中,因为没有实现KoinComponent接口(interface)的东西。最明显的解决方案是将已经注入(inject)的imageManag
我有像这样的顶级功能funsendNotification(context:Context,data:Data){...//alotofcodehere}该功能创建通知,有时通知可以包含图像,所以我必须下载它。我正在使用包裹在接口(interface)ImageManager上的Glide,所以我必须注入(inject)它。我使用Koin进行DI,问题是我不会写valimageManager:ImageManagerbyinject()在我的代码中,因为没有实现KoinComponent接口(interface)的东西。最明显的解决方案是将已经注入(inject)的imageManag