-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathDagger
20 lines (14 loc) · 1.02 KB
/
Dagger
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
## Constructor Injection
- @Inject before constructor to tell dagger how to instantiate object
- @component : before interface to tell dagger to implement this interface to provide us with required fields
## Field Injection: @Inject before fields/variable
## Method Injection: @Inject before method to be called after constructor/creating instance
## Module and Provider: sometimes we can’t modify the constructor of objects (like classes that belong to 3rd party libraries.), in this case we should
- Create module class and annotate it with @module
- Create methods that instantiate this field and annotate it with @Provides
- Add this module to Component class
## Interface Injection:
Create abstract Module class and annotate it with @module
Create abstract method and annotate it with @Binds
Add this module to Component class
@Singleton is the only scope annotation that comes with the javax.inject package. You can use it to annotate ApplicationComponent and the objects you want to reuse across the whole application.