koin

Koin Android: org.koin.error.NoBeanDefFoundException

南笙酒味 提交于 2021-02-18 22:35:08
问题 Got that message error java.lang.RuntimeException: Unable to create application com.app.name.application.MainApplication: org.koin.error.BeanInstanceCreationException: Can't create bean Bean[class=com.app.name.general.preferences.Preferences] due to error : org.koin.error.NoBeanDefFoundException: No definition found to resolve type 'android.app.Application'. Check your module definition at android.app.ActivityThread.handleBindApplication(ActivityThread.java:5830) at android.app.ActivityThread

KoinAppAlreadyStartedException: A Koin Application has already been started

ぃ、小莉子 提交于 2020-12-08 10:51:42
问题 Using koin-2.0.1 for Android testing and unable to test all 3 test together though each test passes separately. class NumberFormatterUtilImplTest : KoinTest { private val numberFormatterUtil: NumberFormatterUtilImpl by inject() @Before fun setUp() { startKoin { modules(utilsModule) } } @Test fun `does formatter returns two digit faction if supplied one digit value`() { val result = numberFormatterUtil.getAdjustedCurrencyRate(18.0) Assert.assertEquals(result, 18.00, 1.0) } @Test fun `does

KoinAppAlreadyStartedException: A Koin Application has already been started

时光怂恿深爱的人放手 提交于 2020-12-08 10:51:28
问题 Using koin-2.0.1 for Android testing and unable to test all 3 test together though each test passes separately. class NumberFormatterUtilImplTest : KoinTest { private val numberFormatterUtil: NumberFormatterUtilImpl by inject() @Before fun setUp() { startKoin { modules(utilsModule) } } @Test fun `does formatter returns two digit faction if supplied one digit value`() { val result = numberFormatterUtil.getAdjustedCurrencyRate(18.0) Assert.assertEquals(result, 18.00, 1.0) } @Test fun `does

放弃dagger?Anrdoi依赖注入框架koin

Deadly 提交于 2020-08-17 03:37:54
Koin 是什么 Koin 是为 Kotlin 开发者提供的一个实用型轻量级依赖注入框架,采用纯 Kotlin 语言编写而成,仅使用功能解析,无代理、无代码生成、无反射。 官网地址 优势 依赖注入好处 增加开发效率、省去重复的简单体力劳动 首先new一个实例的过程是一个重复的简单体力劳动,依赖注入可以把new一个实例的工作做了,因此我们把主要精力集中在关键业务上、同时也能增加开发效率上。 代码更具可读性 省去写单例的方法 解耦 假如不用依赖注入的话,一个类的new代码是非常可能充斥在app的多个类中的,假如该类的构造函数发生变化,那这些涉及到的类都得进行修改。 和dagger相比 编译生成的代码少 编译时间少 上手简单 使用方法 1.添加依赖 // Add Jcenter to your repositories if needed repositories { jcenter() } dependencies { // Koin for Android compile "org.koin:koin-android:$koin_version" } 2.比如创建一个HelloRepository来提供一些数据: interface HelloRepository { fun giveHello(): String } class HelloRepositoryImpl() :

Koin injecting into WorkManager

最后都变了- 提交于 2020-06-27 16:39:07
问题 I have a basic work manager class BackgroundSyncWorker ( appContext: Context, workerParams: WorkerParameters ): Worker(appContext, workerParams) { override fun doWork(): Result { return Result.success() } } And I want to inject my repository into this to do some work in my database. I've set Koin up correctly but can't seem to find a way of how to inject my dependency into the Worker. I've tried inheriting the KoinComponent and trying to do it using that, but by inject() doesn't exist, but

Get the same instance of ViewModel in Fragment which is defined in Activity with parameter

邮差的信 提交于 2020-06-26 12:54:11
问题 So, I am using Koin for dependency injection, Here is what I did inside a activity class ModuleDetailActivity : AppCompatActivity() { private lateinit var moduleId:String private lateinit var levelModule:Level.Module private val moduleViewModel: ModuleViewModel by viewModel { parameterOf(moduleId, levelModule) } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) ... ... moduleId = intent.getString("module_id") levelModule = intent.getParcelable("level

Koin sharedViewModel with SavedStateHandle

余生颓废 提交于 2020-06-16 01:30:32
问题 I have single activity application and number of fragments. Some of these fragments are using my viewmodel, typically like this: private val myViewModel: MyViewModel by sharedViewModel() What if I want to have the model both shared and keep its state with SavedStateHandle? I cannot figure out if this is supported and if so, how it needs to be used (declaring viewmodel as stateViewModel in hosting activity is not working). 回答1: Update: as koin 2.1.6 is around, they introduced org.koin.androidx

How to get Context in unit test to create Room database in memory database object

廉价感情. 提交于 2020-06-15 18:36:47
问题 I'm trying to test this one function in my application repository class which performs a database insertion. I'm using Koin as my dependency injection library. To do the testing I need to create a Database version that gets built in memory. To create that database I need the Android application context. So I created my test class like below. import android.content.Context import androidx.arch.core.executor.testing.InstantTaskExecutorRule import androidx.room.Room import androidx.test.core.app

How to Inject application context from 'app' module to 'network' module using Koin DI

白昼怎懂夜的黑 提交于 2020-05-10 03:53:49
问题 I'm developing an application based on Koin DI (ver : 1.0.1) with 2 modules(:app and :network). I have a requirement in :network module to have "Context". Below is how I implemented: **Module**: val appModule = module { viewModel { LoginViewModel(get()) } } **Activity**: private val viewModel by viewModel<LoginViewModel>() **ViewModel**: class LoginViewModel(val context: Context): ViewModel() { ... // Send "context" to network class in :network module ... } Question: Is there any way we can

Android 开发技术周报 Issue#269

亡梦爱人 提交于 2020-02-26 13:54:36
新闻 谷歌宣布将于下月停用 Sketch 插件 Material Theme Editor [动图]Android 11新增Columbus手势:背面双击可启动相机等应用 Google将限制Android应用在后台访问地理位置数据 XDA大神挖出Android 11新变化:电源菜单要大改 谷歌开放I/O 2020开发者大会注册 Android 新增量文件系统 让你下载未完成前玩游戏 Android 11通知栏隐藏改动曝光:快捷开关可以换装彩色图标 Android 11可快速查看蓝牙耳机所能支持的编码格式 [图]Android 11终于带来原生长截图和录屏功能 更上一层楼: Android 11 首个开发者预览版到来 [图]这不是微软移动系统:达人在Android上打造Windows 10主题 Android开源项目已曝光Pixel 5的注释名称 视频 Android 开发者峰会 2019 中有哪些不容错过的重点? 教程 Android 开发者峰会 2019 常见问题解答 理解循环网络及其在移动端的趣味应用:AI诗人 动态下发 so 库在 Android APK 安装包瘦身方面的应用 开源库 AndroidSnooper Android library to record the network calls through the interceptor mechanism of