![](/img/trans.png)
[英]how to Inject core module objects in feature module
我正在研究一個多模塊 android 項目。 在主模塊中,我們有一個帶有 CoreModule 的 CoreComponent。 CoreModule 提供了一些對象。 我想在不創建新組件的情況下將這些對象注入到我們的功能模塊中。 最好的方法是什么? 主模塊@Component CoreCompo ...
[英]how to Inject core module objects in feature module
我正在研究一個多模塊 android 項目。 在主模塊中,我們有一個帶有 CoreModule 的 CoreComponent。 CoreModule 提供了一些對象。 我想在不創建新組件的情況下將這些對象注入到我們的功能模塊中。 最好的方法是什么? 主模塊@Component CoreCompo ...
[英]Hilt - Question on making a Dao object in a module a Singleton
賞金將在 7 天后到期。 此問題的答案有資格獲得+50聲望賞金。 DIRTY DAVE正在尋找規范的答案。 我正在使用 Google Sunflower 應用程序庫關注Hilt依賴注入教程: https://github.com/android/sunflower/blob/main/app/ ...
[英]How to provide test/mock dependencies for Dagger2 @Subcomponent?
在不同的教程中,我看到了如何將 @Component 的依賴項替換為 mock 或 fakes。 為此,可以使 @Component 的測試變體擴展常規版本。 但是我還沒有找到如何對@Subcomponent 做同樣的事情。 這是我的設置。 零件: 組件的測試版本: 子組件: 用法: 問題是我不能 ...
[英]Dependency injection in Android Library
我正在研究其他應用程序將使用它的 Android 庫。 這個庫不會有任何活動,但它會有片段、VM、域等。到目前為止,我在我的應用程序上使用 Dagger2,但我不確定它在庫中如何工作。 有人有這方面的經驗嗎? 或者也許有人可以推薦其他圖書館用於這種情況(koin?)? 謝謝 ...
[英]Don't Dagger broke an encapsulation principle?
一方面,DI(在我的例子中是 Dagger2)是一個有用的/有用的工具,然而,另一方面,我無法停止認為它打破了封裝原則,我不知道如何生活接着就,隨即:) 例子: 老派方法 所以這里 object B 有一個私有訪問修飾符,這意味着任何要使用 object A 的人都無法訪問 object B(也沒 ...
[英]Can the lifecycleScope for the current Activity be injected into a non-Activity class using Dagger?
這是一個極其簡化的示例: 我想知道是否有更好的方法來解決這個問題。 同樣,這是我所擁有的一個簡化示例。 我意識到一個明顯的替代方法是將 scope 從MyActivity給Foo - 我們只能說這在這種情況下不切實際。 有沒有辦法使用 Dagger 從當前Activity注入lifecycleSc ...
[英]Dagger2 - Module must be set
我有帶有兩個模塊的應用程序組件 - applicationModule 和 activityModule。 在我的MvpApp.java類中,我創建了帶有模塊的組件: 我的ApplicationModule具有帶有Application的構造函數,我發送了它。 但是我的`Activity 模塊有構造 ...
[英]lateinit property has not been initialized [kotlin + dagger 2]
我正在嘗試使用依賴注入來使用數據存儲 API。 數據存儲 API 我在 medium 上寫了這篇文章。 關聯問題我無法將我的 dataStorePref class 注入到我的 IntroScreen class 中,這是我正在使用的 android 中的一個庫 (@Inject lateini ...
[英]Dagger throwing errors after Kotlin integration in a java code
Android 項目代碼庫已滿 java,匕首 2 也在 java 中實現。 我在代碼中集成了 kotlin,每次重建時,Dagger 都會出錯。 (在下面添加) 代碼: build.gradle(項目) build.gradle(應用) gradle.properties gradle ...
[英]Why @ContributesAndroidInjector cant be found by DaggerAndroidProcessor library on the processor path?
我正在實現 Dagger2,當我使用 @ContributesAndroidInjector 時,出現編譯時錯誤: @dagger.android.ContributesAndroidInjector was used,but dagger.android.processor.AndroidPro ...
[英]Inject Map without any @IntoMap bindings
我正在使用 Dagger 將Map<Int,Handler>注入 class。 當在模塊中定義這樣的東西時,它可以完美地工作:@Binds @IntoMap @IntKey(FOO_KEY) Handler bindFooHandler(FooHandler handler); 如果 ...
[英]Unsupported metadata version. Check that your Kotlin version is >= 1.0 after update some plugins
我只是在我的 gradle 文件中更新了以下插件 第二個 gradle 文件我更新了 kotlin 版本 然后我得到了這個錯誤 這是完整的 gradle 項目/模塊文件 這個構建 gradle 應用依賴 ...
[英]How to initialize ViewModel when using Dagger?
我開始學習匕首。 我嘗試從 ViewModel 獲取字符串,出現錯誤: MainActivity : StringFragment : StringRepository : StringUseCase : StringViewModel : App : AppComponent : ...
[英]Cannot create an instance of class ViewModel - android
我有如下ViewModel : 這是LoginViewModelFactory : 我像下面這樣編輯但不起作用: 和: 和這里: 和: 和: 我無法調用LoginViewModel ...
[英]Android background service calls onDestroy() before coroutine finishes work
我在 Android 中有后台服務來處理 Google Firebase 推送通知:class MyFirebaseMessagingService : FirebaseMessagingService() { @Inject lateinit var repository: R ...
[英]Fallback / default value for @BindsInstance object
// Previously, our Api looks like this: @Component(modules = ApiManagerModule.class) public interface ApiComponent { @Component.Builder interfa ...
[英]Use one binding as default when multiple bindings are present in Dagger
我有兩個用於單個 BaseClass 的綁定。 例如 我不想在所有需要 Base 作為依賴項的地方都使用 @Named("b") ,但是除非明確指定 @Named,否則默認情況下應該使用名為 "B" 的綁定。 ...
[英]I'm getting Android dagger cannot be provided without an Provides-annotated method inside Activity file
在一個大型代碼庫中,我關注 3 個類。 DataDao.kt、DataManager.kt 和 InfoPageActivity.kt。 DataManager 注入 DataDao 並獲得 function 用於檢索數據。 我在 InfoPageActivity 中注入這個 DataManag ...
[英]How to debug Dagger2 not generating components
有沒有辦法讓匕首吐出為什么它沒有生成特定的組件? 我嘗試重構我們的一些模塊並最終破壞了一些東西,但我真的不知道我破壞了什么! 我所看到的是我所有的DaggerFoo組件都丟失了,因為 dagger 顯然是默默地失敗了。 我已經嘗試使用冗長和更高的最大錯誤進行編譯,但我仍然完全沒有看到 Dagger ...
[英]Hilt migration for interface having multiple implementations and injected in one generic file constructor gives error: [Dagger/DuplicateBindings]
我正在嘗試將現有的 Dagger 實現遷移到 Hilt。 我有一個由多個類實現的通用接口。 然后是實現類 我有一個演示者,它在構造函數中注入了這個接口,而演示者又被注入到一個片段中 現在,當我嘗試使用 Hilt 模塊遷移此層次結構時,出現重復綁定錯誤 錯誤:[Dagger/DuplicateBin ...