View di12.kt
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
class MainActivity: AppCompatActivity() { | |
@Inject | |
lateinit var mainPresenter: MainPresenter | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
Injector.inject(MainModule::class, this) | |
View di11.kt
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
object Injector { | |
fun <T : InjectorModule, R : Any> inject(kClass: KClass<T>, entryPointClass: R) { | |
// get all provider methods | |
val methods = kClass.java.declaredMethods | |
.filter { method -> method.isAnnotationPresent(Provides::class.java) } | |
// construct module instance | |
val moduleInstance = kClass.java.newInstance() | |
View di10.kt
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
class MainActivity: AppCompatActivity() { | |
@Inject | |
lateinit var mainPresenter: MainPresenter | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
// inject mainPresenter here | |
View d19.kt
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
@Retention(AnnotationRetention.RUNTIME) | |
@Target(AnnotationTarget.FIELD, AnnotationTarget.CONSTRUCTOR) | |
annotation class Inject |
View di8.kt
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
object Injector { | |
fun <T : InjectorModule, R : Any> inject(kClass: KClass<T>, entryPointClass: R) { | |
// get all provider methods | |
val methods = kClass.java.declaredMethods | |
.filter { method -> method.isAnnotationPresent(Provides::class.java) } | |
// construct module instance | |
val moduleInstance = kClass.java.newInstance() | |
View InjectorModule.kt
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
interface InjectorModule { | |
} |
View di7.kt
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
class MainModule: InjectorModule { | |
@Provides | |
fun provideMainPresenter(): MainPresenter { | |
return MainPresenterImpl() | |
} | |
} |
View di6.kt
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
@Retention(AnnotationRetention.RUNTIME) | |
@Target(AnnotationTarget.FUNCTION) | |
annotation class Provides |
View di5.kt
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
class MainModule: InjectorModule { | |
fun provideMainPresenter(): MainPresenter { | |
return MainPresenterImpl() | |
} | |
} |
View d14.kt
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
object Injector { | |
fun inject() | |
} |
NewerOlder