🏴☠️
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
/** | |
* Using ComputerComponent as dependency to MiningRigComponent | |
*/ | |
@Component(dependency = arrayOf(ComputerComponent::class)) | |
interface MiningRigComponent |
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
/** | |
* Declaring a activity bindings using @ContributesAndroidInjector and @Activity scope (custom scope) | |
*/ | |
@Module | |
abstract class ActivityBindings { | |
@ActivityScope | |
@ContributesAndroidInjector | |
abstract fun contributeHomeActivity(): HomeActivity |
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
/** | |
* Declaring application implementing `HasActivityInjector` with `DispatchingAndroidInjector` | |
*/ | |
class DefineApplication : Application(), HasActivityInjector { | |
override fun activityInjector(): DispatchingAndroidInjector<Activity> = mAndroidInjector | |
@Inject | |
lateinit var mAndroidInjector: DispatchingAndroidInjector<Activity> |
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
/** | |
* An activity with a `HomeViewModel` dependency | |
*/ | |
class HomeActivity : AppCompatActivity() { | |
@Inject | |
lateinit var homeViewModel: HomeViewModel // Requesting the dependency | |
override fun onCreate(savedInstanceState: Bundle?) { |
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
/** | |
* HomeViewModel with `@Inject`able constructor | |
*/ | |
class HomeViewModel @Inject constructor(private val resources: Resources, | |
private val preferenceUtils: PreferenceUtils, | |
private val defineRepository: DefineRepository) {} |
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
/** | |
* Fragment with dependency `ConnectionUtils` | |
*/ | |
class HomeFragment: Fragment() { | |
@Inject | |
lateinit var connectionUtils: ConnectionUtils // Requesting our dependency | |
override fun onAttach(context: Context?) { |
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
/** | |
* An activity implementing `HasSupportFragmentInjector` and with an instance of `DispatchingAndroidInjector<Fragment>` | |
* for fragment injection. | |
*/ | |
class HomeActivity : HasSupportFragmentInjector { | |
@Inject | |
lateinit var mAndroidInjector: DispatchingAndroidInjector<Fragment> | |
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
/** | |
* Building `ComputerComponent` and getting a dependency | |
*/ | |
class ComputerApp { | |
@Inject lateinit var computer: Computer | |
} | |
fun main(args: Array<String>) { | |
val computerComponent = DaggerComputerComponent |
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
/** | |
* Declaring application with `ComputerComponent` instance | |
*/ | |
class MyApplication: Application() { | |
lateinit var computerComponent: ComputerComponent // Declaring our component instance | |
@Override | |
public void onCreate() { |
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
/** | |
* Activity handling it's injection | |
*/ | |
class MyActivity { | |
@Inject | |
lateinit var computer: Computer // Requesting the dependency | |
override fun onCreate(savedInstanceState: Bundle?) { |