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
/** | |
* Contains bindings to ensure the usability of {@code dagger.android} framework classes. This | |
* module should be installed in the component that is used to inject the {@link | |
* android.app.Application} class. | |
*/ | |
@Beta | |
@Module | |
public abstract class AndroidInjectionModule { | |
@Multibinds | |
abstract Map<Class<? extends Activity>, AndroidInjector.Factory<? extends Activity>> |
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
@Module | |
public class FlombulatorModule { | |
@Provides | |
Flumbolator provideFlumBolator() { | |
System.out.println("I'm the mighty real implementation, give me a break"); | |
return new Flumbolator(); | |
} | |
} |
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
FlumbolatorComponent component = DaggerFlumbolatorComponent.builder() | |
.anyDependencyModule(new DependencyModule(params)) | |
.build(); | |
component.inject(this); |
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
@Subcomponent(modules = { | |
FlombulatorModule.class, | |
MainActivitySubComponent.MainActivityModule.class | |
}) | |
public interface MainActivitySubComponent extends AndroidInjector<MainActivity> { | |
@Module | |
class MainActivityModule {} |
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
@Module(subcomponents = { | |
MainActivitySubComponent.class, | |
SecondaryActivitySubComponent.class | |
}) | |
public abstract class BindingModule { | |
@Binds | |
@IntoMap | |
@ActivityKey(MainActivity.class) | |
abstract AndroidInjector.Factory<? extends Activity> bindMainActivityInjectorFactory(MainActivitySubComponent.Builder builder); |
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
@Component( | |
modules = { | |
AndroidInjectionModule.class, | |
BindingModule.class, | |
MyApplicationComponent.AppModule.class | |
}) | |
interface MyApplicationComponent { | |
void inject(Dagger2application dagger2application); |
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
public class Dagger2application extends Application implements HasDispatchingActivityInjector { | |
@Inject | |
DispatchingAndroidInjector<Activity> dispatchingActivityInjector; | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
DaggerMyApplicationComponent.create().inject(this); | |
} |
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
@Config(constants = BuildConfig.class, sdk = 21, application = TestApplication.class) | |
@RunWith(RobolectricTestRunner.class) | |
public class TestMainActivity { | |
private MainActivity mainActivity; | |
@Before | |
public void setUp() throws Exception { | |
} |
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
public class TestApplication extends Application implements HasDispatchingActivityInjector { | |
@Inject | |
DispatchingAndroidInjector<Activity> dispatchingActivityInjector; | |
@Override | |
public void onCreate() { | |
super.onCreate(); | |
System.out.println("HEY IM UP TESTING APPLICATION COMPONENT ==========================+>"); | |
DaggerTestApplicationComponent.create().inject(this); | |
} |
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
@Component( | |
modules = { | |
AndroidInjectionModule.class, | |
TestBindingModule.class, | |
TestApplicationComponent.TestAppModule.class | |
}) | |
interface TestApplicationComponent { | |
void inject(TestApplication app); |