Skip to content

Instantly share code, notes, and snippets.

@jixiaoyong
Last active January 26, 2019 10:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jixiaoyong/8abd44901a2816e2b6722566bb8f08d8 to your computer and use it in GitHub Desktop.
Save jixiaoyong/8abd44901a2816e2b6722566bb8f08d8 to your computer and use it in GitHub Desktop.
介绍了Dagger 2 中的 @Inject@component 的使用
//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