-
Notifications
You must be signed in to change notification settings - Fork 1
/
short DependencyInjection.java
53 lines (33 loc) · 1.27 KB
/
short DependencyInjection.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Dependency Injection
1. cearte module
class with annotation @module
1.1 Provider method
cearte method inside module class with annotation @Provider
2. Component
create interface with anotation @Component with parameter of list of module related to this component
3. setup dagger in application class
4 Multiple dependency
App => SharedprefHelper => Sharedpreference => context
'AppComponent'
1. Create 2 methods
- sharedpref
- context
AppModule
1. provide 2 things
- sharedpref
- context
SharedPrefModule
provide sharedPrefhelper which accepts 1 parameter SharedPref Object
returns sharedPrefHelper object
'SharedprefComponent'
As this component dependent on AppComponent for Sharedpreference object and context object
we need add AppComponent as dependencies in @Component tag
next
And normal inject method
'Application'
while creating SharedprefComponent as normal we add SharedPrefModule and as this component is dependent on AppModule
we need to add appModule too this component.
5. SubComponent
we use anotation @SubComponent
we add this component in parentComponent like normal method
as like dpendencies we dont need to add this SubComponent to parentComponent while Instantiation.