Created
March 19, 2013 19:47
-
-
Save adennie/5199473 to your computer and use it in GitHub Desktop.
inherited qualified provider not found when checking for completeness of bindings
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.fizzbuzz.daggerexperiments; | |
import dagger.Module; | |
import dagger.Provides; | |
import javax.inject.Inject; | |
import javax.inject.Qualifier; | |
import java.lang.annotation.Documented; | |
import java.lang.annotation.Retention; | |
import java.lang.annotation.Target; | |
import static java.lang.annotation.ElementType.*; | |
import static java.lang.annotation.RetentionPolicy.RUNTIME; | |
public class ContextHoldingModules2 { | |
public static void main(String[] args) { | |
} | |
@Qualifier | |
@Target({FIELD, PARAMETER, METHOD}) | |
@Documented | |
@Retention(RUNTIME) | |
public @interface Application { | |
} | |
public static class Context { | |
} | |
public static class HasInjectedContext { | |
@Inject @Application | |
Context mContext; | |
} | |
@Module | |
public static class BaseModule { | |
private Context mContext; | |
public BaseModule(Context context) { | |
mContext = context; | |
} | |
@Provides | |
@Application | |
public Context provideContext() { | |
return mContext; | |
} | |
} | |
@Module (entryPoints = {Context.class, HasInjectedContext.class}) | |
public static class DerivedModule | |
extends BaseModule{ | |
public DerivedModule() { | |
super(new Context()); | |
} | |
} | |
} |
Hmmm . . . I'm tempted to forbid subclassing modules altogether. Composition instead of inheritance, right?
Well, if you're referring to something like ObjectGraph.create(new MyAppModule(), new AppModule(new Context())), where AppModule has the Context provider, that might work. I'll try it out.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ContextHoldingModules2.java:[51,18] No binding for @com.fizzbuzz.daggerexperiments.ContextHoldingModules2$Application()/com.fizzbuzz.daggerexperiments.ContextHoldingModules2$Context required by com.fizzbuzz.daggerexperiments.ContextHoldingModules2.HasInjectedContext for com.fizzbuzz.daggerexperiments.ContextHoldingModules2.DerivedModule