This power point presentation explains Dependency Injection in Android with Dagger 2. This report PPT designed and presented by Cumulations Technologies team member (http://www.cumulations.com/)
2. What is Dependency Injection ?
Its Famous and everybody is talking about it.
You might be using it without writing the independent examples.
Butterknife is the hint
3. What is Dependency ?
Class Car{
getPermittedSpeed(String country){
TrafficRules rules=new Traficrules(); // Dependency
rules.getSpeed(country);
}
getAgeLimit(String country){
TrafficRules rules=new Traficrules(); // Dependency
rules.getAgeLimit(country);
}
}
4. Class Car{
getPermittedSpeed(String country,TrafficRules rule){
rule.getSpeed(country);
}
getAgeLimit(String country, TrafficRules rule){
rule.getAgeLimit();
}
}
This is Dependency Injection
// Only god can create perfectly not you, so dont create us simply call us
5. Class Car{
TrafficRules rules;
Car(){
rules=new TrafficRules();
}
// Dependency Resolved
getPermittedSpeed(String country){
rules.getSpeed(country);
}
getAgeLimit(String country)...
}
Wrong ! You cannot create you
should only call
6. Class Car{
TrafficRules rules;
Car(TrafficRules rules){
this.rules= rules;
}
// Dependency Resolved
getPermittedSpeed(String country){
rules.getSpeed(country);
}
getAgeLimit(String country)...
}
Now you are a good guy!
This is correct as we are not
creating but calling
8. Class Car{
@Inject
TrafficRules rules; // Will be done by Libraries like Dagger ?
// Dependency Resolved
getPermittedSpeed(String country){
rules.getSpeed(country);
}
}
Welcome to Dagger 2
9. How did dagger2 know to create object ?
Secret: You will tell Dagger2, what objects it has to
create
10. Dagger2 usage
Tell 3 Things to Dagger2
> What are the Objects Dagger 2 has to create for you
> What functions it has call for creating these Objects ?
> Where all it has to inject these pre created Objects
11. Dagger2 usage
Tell 3 Things to Dagger2
> What are the Objects Dagger 2 has to create for you
> What functions it has call for creating these Objects ?
> Where all it has to inject these pre created Objects
@Modules
@Provides
@Component