Dependency Injection in Android With Dagger2 (2)

Replace Pure Dependency Injection with Dagger2

Guowei Lv

1 minute read

Previous post we set up the so called Pure Dependency Injection. Now let’s replace that with Dagger2 balantly.

Convert the composition roots into dagger’s @Modules.

Create @Component to hold each @Module.

Create @Scopes and use it to scope the objects we want only 1 instance in the component.

Now it looks like this:

comments powered by Disqus