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 = [MainActivityModule.FragmentBindings::class]) | |
class MainActivityModule { | |
@Module | |
interface FragmentBindings { | |
@ContributesAndroidInjector(modules = [MainFragmentModule::class]) | |
fun bindMainFragment() : MainFragment | |
} | |
@Provides | |
@MainActivityScope |
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
class MainFragment : Fragment() { | |
@Inject | |
lateinit var hero : Hero | |
override fun onAttach(context: Context?) { | |
AndroidSupportInjection.inject(this) | |
super.onAttach(context) | |
Log.d("InjectionTest", hero.name) | |
} |
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 | |
class MainActivityModule { | |
@Provides | |
@MainActivityScope | |
fun provideWarrior(): Warrior = Warrior("Hercules", "Sword") | |
@Provides | |
@MainActivityScope | |
fun provideActivity(mainActivity: MainActivity) : MainActivity = mainActivity |
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 ActivityModule { | |
@MainActivityScope | |
@ContributesAndroidInjector(modules = [MainActivityModule::class]) | |
abstract fun bindMainActivity(): MainActivity | |
} |
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 = [ | |
AndroidSupportInjectionModule::class, | |
ActivityModule::class | |
] | |
) | |
interface AppComponent { | |
@Component.Builder |
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(subcomponents = [MainActivitySubcomponent::class]) | |
abstract class ActivityModule { | |
@Binds | |
@IntoMap | |
@ClassKey(MainActivity::class) | |
abstract fun bindMainActivityInjectorFactory(builder: MainActivitySubcomponent.Builder): AndroidInjector.Factory<*> | |
} |
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
@MainActivityScope | |
@Subcomponent(modules = [MainActivityModule::class]) | |
interface MainActivitySubcomponent : AndroidInjector<MainActivity> { | |
@Subcomponent.Builder | |
abstract class Builder : AndroidInjector.Builder<MainActivity>() | |
} |
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 | |
class MainActivityModule { | |
@Provides | |
@MainActivityScope | |
fun provideWarrior(): Warrior = Warrior("Hercules", "Sword") | |
} |
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
class MainActivity : AppCompatActivity() { | |
@Inject | |
lateinit var warrior: Warrior | |
override fun onCreate(savedInstanceState: Bundle?) { | |
AndroidInjection.inject(this) | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) |
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
data class Warrior(val name: String, val weapon: String) |
NewerOlder