dagger-2

Dagger 2: @Component.Builder is missing setters for required modules or components: [appi.example.com.dagger.AppModule]`

£可爱£侵袭症+ 提交于 2019-11-28 16:26:25
问题 I'm configuring the new Dagger Android module but I got this error Here's my Component: @AppScope @Component(modules = {AppModule.class, NetModule.class}) public interface AppComponent { @Component.Builder interface Builder { @BindsInstance Builder application(ExampleApplication application); @BindsInstance Builder appModule(AppModule appModule); @BindsInstance Builder netModule(NetModule netModule); AppComponent build(); } void inject(ExampleApplication __); ... Which I build like this in my

Dagger 2.2 component builder module method deprecated

半腔热情 提交于 2019-11-28 16:17:47
I started using dagger 2.2 and the module methods in the Component builder are deprecated. This is my Application component : @Component(modules = ApplicationModule.class) public interface ApplicationComponent { void inject(Application application); } And the Application module: @Module public class ApplicationModule { Application application; public ApplicationModule(Application application) { this.application = application; } @Provides @Singleton Application providesApplication() { return application; } } Here is the generated class: @Generated( value = "dagger.internal.codegen

Dagger- Should we create each component and module for each Activity/ Fragment

让人想犯罪 __ 提交于 2019-11-28 15:03:43
I've been working with dagger2 for a while. And I got confused wether to create an own component/module for each Activity/ Fragment. Please help me clarify this: For example, We have an app, and the app has about 50 screens. We will implement the code following the MVP pattern and Dagger2 for DI. Suppose that we have 50 activities and 50 presenters. In my opinion, usually we should organize the code like this : Create an AppComponent and AppModule which will provide all objects that will be used while the app is open. @Module public class AppModule { private final MyApplicationClass

Can I use some kind of assisted Inject with Dagger?

帅比萌擦擦* 提交于 2019-11-28 14:16:19
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? Because factories are a separate type of boilerplate to optimize away ( see mailing list discussion here ), Dagger leaves it

How to make Jersey work with Dagger dependency injection?

不打扰是莪最后的温柔 提交于 2019-11-28 11:56:01
Jersey normally uses HK2 dependency injection, but I would like to use Jersey with Dagger 2. Both Dagger and HK2 implement JSR 330, which I have taken as evidence that this should be possible without too much effort. I found ways to make Jersey work with CDI (e.g. Weld), Spring DI and Guice, but I can't find anything on Dagger. To provide some context: I'm running a Grizzly–Jersey server in an SE environment, not in an EE container. My Maven project has com.google.dagger:dagger and org.glassfish.jersey.containers:jersey-container-grizzly2-http as dependencies, but not org.glassfish.jersey

Dagger2 scopes and activity lifecycle

穿精又带淫゛_ 提交于 2019-11-28 11:31:57
I have an Android Activity that I'm using Dagger2 to inject a Presenter into. I'd like my Presenter to be capable of holding state even if a configuration change occurs. For instance, I'm going to use the Presenter to kick off a network call and if the user rotates the device while the network call is in-flight I'd like to be able to receive the response after the device finishes its rotation and not have to restart the call. I'm getting tripped up because if I scope the instance of Presenter to the Activity's life, then isn't there a chance that the Presenter would be garbage collected when

Implementing a simple Dagger2 sample

主宰稳场 提交于 2019-11-28 11:07:03
问题 I'm new using Dagger2 (I always used Koin) and I'm trying to implement a simple sample but I don't really know what I'm missing. This is what I got so far. app.gradle : ext.daggerVersion = '2.23.2' implementation "com.google.dagger:dagger:$daggerVersion" implementation "com.google.dagger:dagger-android-support:$daggerVersion" kapt "com.google.dagger:dagger-android-processor:$daggerVersion" kapt "com.google.dagger:dagger-compiler:$daggerVersion" AppModule.kt : @Module class AppModule {

Dagger2 and Android

五迷三道 提交于 2019-11-28 10:25:11
I am trying to implement Dagger Dependency Injection into my app but I am having a hard time understanding how it works, especially coming from Spring where DI was much easier and much more declarative. What I want to do is have a bunch of inject-ready objects that can be used throughout my app, that is the SharedPreferences, the Network objects (OkHttp, Retrofit, Picasso...), and EventBus and a SchedulerProvider object for RxJava. This sample seems to offer everything I need but I am having trouble grasping some concepts. In this other sample referenced in the previous page they create a

Dagger 2 generated test component not recognized

浪子不回头ぞ 提交于 2019-11-28 10:03:27
I'm hoping that this is just something I'm doing wrong here. I'm trying to use Dagger 2.0 to inject dependencies for my JUnit tests ( not Espresso tests , just pure JUnit). So, I have a 'main' java module and a 'test' java module. In the main module, I've got a Dagger Module and a Component: @Module public class MainModule { @Provides public Widget provideWidget() { return new ConcreteWidget(); } } ... @Component (modules = MainModule.class) public interface MainComponent { void inject(WidgetConsumer consumer); } And in my test module, I have the following: @Module public class TestModule {

Dagger 2 multibindings with Kotlin

[亡魂溺海] 提交于 2019-11-28 09:38:26
I have the following snippet in my dagger 2 module @Singleton @Provides @ElementsIntoSet fun providesQueries(foo: Foo): Set<Foo>{ val queries = LinkedHashSet<Foo>() queries.add(foo) return queries } I try to inject into in this way @Inject lateinit var foo: Set<Foo> But dagger shows an error which says that Dagger cannot provides java.util.Set without @Provides or @Produces method. I did the same in java and it worked. Does somebody know why is it failing? As it described in the Kotlin reference To make Kotlin APIs work in Java we generate Box<Super> as Box<? extends Super> for covariantly