Created
April 9, 2018 02:27
-
-
Save vincent-paing/e03be92e47e26ae14ff73a95381bd06b to your computer and use it in GitHub Desktop.
Dagger Stuffs
This file contains hidden or 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
@Singleton | |
@Component( | |
modules = arrayOf( | |
AndroidSupportInjectionModule::class, ApplicationModule::class, NetworkModule::class, | |
BindingModule::class | |
) | |
) | |
interface ApplicationComponent { | |
@Component.Builder | |
interface Builder { | |
@BindsInstance | |
fun application(application: Application): Builder | |
fun build(): ApplicationComponent | |
} | |
fun inject(app: Application) | |
} |
This file contains hidden or 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( | |
includes = [(SubComponenetModule::class), (NetworkModule::class), (PersistenceModule::class)] | |
) | |
class ApplicationModule { | |
@Provides | |
fun provideContext(application: MMPluseNewsApplication): Context { | |
return application.getApplicationContext() | |
} | |
@Provides | |
fun providesNetworkManager(networkManagerImpl: NetworkManagerImpl): NetworkManager { | |
return networkManagerImpl | |
} | |
@Provides | |
fun providesPersistenceManager(persistenceManagerImpl: PersistenceManagerImpl): PersistenceManager { | |
return persistenceManagerImpl | |
} | |
@Provides | |
fun providesDataManager(dataManagerImpl: DataManagerImpl): DataManager { | |
return dataManagerImpl | |
} | |
@Provides | |
fun providesErrorMessageFactory(errorMessageFactoryImpl: ErrorMessageFactoryImpl): ErrorMessageFactory { | |
return errorMessageFactoryImpl | |
} | |
@Provides | |
fun providesDeviceIdManager(deviceIdAndroidManager: DeviceIdAndroidManager): DeviceIdManager { | |
return deviceIdAndroidManager | |
} | |
} |
This file contains hidden or 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 | |
abstract class BindingModule { | |
@Binds | |
@IntoMap | |
@FragmentKey(SignUpFragment::class) | |
internal abstract fun bindSignUpFragment( | |
builder: SignUpFragmentSubComponent.Builder | |
): AndroidInjector.Factory<out Fragment> | |
@Binds | |
@IntoMap | |
@FragmentKey(SignInFragment::class) | |
internal abstract fun bindSignInFragment( | |
builder: SignInFragmentSubComponent.Builder | |
): AndroidInjector.Factory<out Fragment> | |
@Binds | |
@IntoMap | |
@FragmentKey(NewsFragment::class) | |
internal abstract fun bindNewsFragment( | |
builder: NewsFragmentSubComponent.Builder | |
): AndroidInjector.Factory<out Fragment> | |
@Binds | |
@IntoMap | |
@ActivityKey(MainActivity::class) | |
internal abstract fun bindMainActivity( | |
builder: MainActivitySubComponent.Builder | |
): AndroidInjector.Factory<out Activity> | |
@Binds | |
@IntoMap | |
@ActivityKey(NewsDetailActivity::class) | |
internal abstract fun bindNewsDetailActivity( | |
builder: NewsDetailSubComponent.Builder | |
): AndroidInjector.Factory<out Activity> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment