Android Dependency Injection with Dagger 2 suggest change

Connecting Modules with Inject

The connection between the provider of dependencies, @Module, and the classes requesting them through @Inject is made using @Component, which is an interface:

import javax.inject.Singleton;
import dagger.Component;

@Singleton
@Component(modules = {VehicleModule.class})
public interface VehicleComponent {
    Vehicle provideVehicle();
}

For the @Component annotation, you have to specify which modules are going to be used. In this example VehicleModule is used, which is defined in this example. If you need to use more modules, then just add them using a comma as a separator.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents