dagger

Can I use some kind of assisted Inject with Dagger?

99封情书 提交于 2020-01-19 04:11:05
问题 With Google Guice or Gin I can specify parameter with are not controlled by the dependency injection framework: class SomeEditor { @Inject public SomeEditor(SomeClassA a, @Assisted("stage") SomeClassB b) { } } The assisted parameter stage is specified at the time an instance of SomeEditor is created. The instance of SomeClassA is taken from the object graph and the instance of SomeClassB is taken from the caller at runtime. Is there a similar way of doing this in Dagger? 回答1: Because

Can I use some kind of assisted Inject with Dagger?

喜你入骨 提交于 2020-01-19 04:10:37
问题 With Google Guice or Gin I can specify parameter with are not controlled by the dependency injection framework: class SomeEditor { @Inject public SomeEditor(SomeClassA a, @Assisted("stage") SomeClassB b) { } } The assisted parameter stage is specified at the time an instance of SomeEditor is created. The instance of SomeClassA is taken from the object graph and the instance of SomeClassB is taken from the caller at runtime. Is there a similar way of doing this in Dagger? 回答1: Because

Android-Dagger2和MVP使用示例

試著忘記壹切 提交于 2020-01-16 12:09:49
Dagger使用整理: https://blog.csdn.net/ahou2468/article/details/103952052 MVP使用整理: https://blog.csdn.net/ahou2468/article/details/103975635 MVP-模型-视图-表现层(Presenter):Presenter相当于Model和View通信的桥梁,控制着程序的全部逻辑,在Presenter将View和Model对象注入到Presenter; Dagger:是一个依赖注入框架,Dagger负责实现View和Model注入到Presenter; 目录 1.MVP实现 1.1定义Presenter和View接口 1.2Presenter实现 1.3实现View 2.Dagger实现MVP中依赖的注入 2.1定义Module和Provider实例提供方 2.2定义Component 2.3实现Dagger中Component和与MVP的绑定 a.将会生成Dagger创建Model的工厂方法:(依赖注入提供方) b.将会生成Dagger创建实现Component的接口的方法:(依赖注入具体消费方) c.在Activity/Fragment中调用Component接口的实现类,实现绑定操作 1.MVP实现 1.1定义Presenter和View接口 Presenter

How to inject activity into another class using dagger.android?

坚强是说给别人听的谎言 提交于 2020-01-15 08:13:31
问题 I'm using the new dagger.android method to inject activities, but I wonder what to do if you want to inject Activity to a class? Maybe a Navigator class which needs the current activity: package com.abydos.messenger.ui import android.app.Activity import com.abydos.messenger.ui.register.RegisterActivity import org.jetbrains.anko.startActivity import javax.inject.Inject class Navigator @Inject constructor(private val activity: Activity) { fun register() { activity.startActivity<RegisterActivity

Add Retrofit Requestinterceptor with Dagger at runtime

泄露秘密 提交于 2020-01-13 13:52:13
问题 I'm using dagger and retrofit. I inject my Retrofit services with Dagger. Now i wanna do a authorization request to get an accessToken. Afterwards i want to enhance my api module with an Request interceptor to use this access token for future requests. My idea is to use the ObjectGraph.plus() method after i received the access token, but i'm not sure if this is the best way to do it. Can someone point me to the right direction or maybe is there an example project on github ? 回答1: The key is

Inject database in a ContentProvider with dagger

本秂侑毒 提交于 2020-01-12 14:12:16
问题 I want to inject a singleton SqliteOpenHelper in a ContentProvider . However, it seems that the ContentProvider instance is being built before the Application instance is being created ( getApplicationContext() returns null). When can I inject the database? I've tried in the constructor and in the onCreate() method of the ContentProvider . 回答1: I faced the same issue and had to defer injection until the database was needed. You might be able to use Dagger's lazy injection to achieve the same

Inject database in a ContentProvider with dagger

巧了我就是萌 提交于 2020-01-12 14:08:38
问题 I want to inject a singleton SqliteOpenHelper in a ContentProvider . However, it seems that the ContentProvider instance is being built before the Application instance is being created ( getApplicationContext() returns null). When can I inject the database? I've tried in the constructor and in the onCreate() method of the ContentProvider . 回答1: I faced the same issue and had to defer injection until the database was needed. You might be able to use Dagger's lazy injection to achieve the same

Dagger 1.x @Inject throws an IllegalArgumentException

早过忘川 提交于 2020-01-06 14:13:25
问题 I want to replace our component registry (with dexfile class loader magic) with an dependency injection framework for Android. The first try is dagger. When trying I get the following error: 11-06 13:05:41.040 16269-16269/com.daggertoolkitexample E/AndroidRuntime﹕ FATAL EXCEPTION: main java.lang.RuntimeException: Unable to start activity ComponentInfo{daggertoolkitexample/com.dagger.MyActivity}: java.lang.IllegalArgumentException: No inject registered for members/com.dagger.MyActivity. You

error: [Dagger/DuplicateBindings] com.example.StartRouter is bound multiple times?

荒凉一梦 提交于 2020-01-06 09:01:15
问题 I have a class StartRouter . I want to provide different instances of this class to each activity, and keep it alive as long as activity is alive (for that I made @ActivityScope ). Problem is that it does not do that in my code. It seems as dagger provides one instance per annotation, in my case, once for the @ActivityScope . This scope is a custom dagger scope. Here are my two modules (One for each activity), first module: @Module public class SplashModule { @Provides SplashVMFactory

dagger2 GC overhead limit exceeded

血红的双手。 提交于 2020-01-05 04:04:10
问题 I'm following the Dagger2 sample of TODO app but encounted with OutOfMemoryError: GC overhead limit exceeded. Along with it are 600+ warning likes: warning: Ignoring InnerClasses attribute for an anonymous inner class (org.eclipse.osgi.internal.baseadaptor.BaseStorage$StateSaver$1) that doesn't come with an associated EnclosingMethod attribute. This class was probably produced by a compiler that did not target the modern .class file format. The recommended solution is to recompile the class