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 mainPresenter: MainPresenter | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| Injector.inject(MainModule::class, this) | |
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
| 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() | |
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 mainPresenter: MainPresenter | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| // inject mainPresenter here | |
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
| @Retention(AnnotationRetention.RUNTIME) | |
| @Target(AnnotationTarget.FIELD, AnnotationTarget.CONSTRUCTOR) | |
| annotation class Inject |
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
| 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() | |
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
| interface InjectorModule { | |
| } |
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 MainModule: InjectorModule { | |
| @Provides | |
| fun provideMainPresenter(): MainPresenter { | |
| return MainPresenterImpl() | |
| } | |
| } |
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
| @Retention(AnnotationRetention.RUNTIME) | |
| @Target(AnnotationTarget.FUNCTION) | |
| annotation class Provides |
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 MainModule: InjectorModule { | |
| fun provideMainPresenter(): MainPresenter { | |
| return MainPresenterImpl() | |
| } | |
| } |
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
| object Injector { | |
| fun inject() | |
| } |
NewerOlder