Last active
January 26, 2019 10:58
-
-
Save jixiaoyong/8abd44901a2816e2b6722566bb8f08d8 to your computer and use it in GitHub Desktop.
介绍了Dagger 2 中的 @Inject 和 @component 的使用
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
//Dagger2_basic_guide_line_part1 | |
/** | |
* author: jixiaoyong | |
* email: jixiaoyong1995@gmail.com | |
* website: https://jixiaoyong.github.io | |
* date: 2019/1/25 | |
* description: 介绍了Dagger 2 中的 @Inject 和 @Component 的使用 | |
*/ | |
class Service @Inject constructor() | |
class Client{ | |
@Inject | |
lateinit var service: Service | |
init { | |
//方式❶ | |
DaggerClientComponent.create().inject(this) | |
//方式❷ DaggerClientComponent.builder().build().inject(this) | |
val newService = service | |
} | |
} | |
@Component | |
interface ClientComponent{ | |
fun inject(client: Client) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment