An introduction covered with example codes to demonstrate the need and how to use in the simplest way possible the dependency injection framework "Dagger".
protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Api api = new Api(); Cache cache = new Cache(); Repository repository = new Repository(api, cache); presenter = new Presenter(repository); } } Activity.java
protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); Api api = new Api(); Cache cache = new Cache(); Repository repository = new Repository(api, cache); presenter = new Presenter(repository); } } Activity.java
CACHE_SIZE_10_MB = 10 * 1024 * 1024; private static final int TIMEOUT = 20; @Provides public Presenter providesPresenter(Repository repository) { return new Presenter(repository); } @Provides @Reusable public Repository repository(Cache cache, Api api) { return new Repository(cache, api); } @Provides @Singleton public Cache providesCache() { return new Cache(CACHE_SIZE_10_MB); } @Provides @Reusable public Api providesApi() { return new Api(TIMEOUT); } }
CACHE_SIZE_10_MB = 10 * 1024 * 1024; private static final int TIMEOUT = 20; @Provides public Presenter providesPresenter(Repository repository) { return new Presenter(repository); } @Provides @Reusable public Repository repository(Cache cache, Api api) { return new Repository(cache, api); } @Provides @Singleton public Cache providesCache() { return new Cache(CACHE_SIZE_10_MB); } @Provides @Reusable public Api providesApi() { return new Api(TIMEOUT); } }
CACHE_SIZE_10_MB = 10 * 1024 * 1024; private static final int TIMEOUT = 20; @Provides public Presenter providesPresenter(Repository repository) { return new Presenter(repository); } @Provides @Reusable public Repository repository(Cache cache, Api api) { return new Repository(cache, api); } @Provides @Singleton public Cache providesCache() { return new Cache(CACHE_SIZE_10_MB); } @Provides @Reusable public Api providesApi() { return new Api(TIMEOUT); } }
CACHE_SIZE_10_MB = 10 * 1024 * 1024; private static final int TIMEOUT = 20; @Provides public Presenter providesPresenter(Repository repository) { return new Presenter(repository); } @Provides @Reusable public Repository repository(Cache cache, Api api) { return new Repository(cache, api); } @Provides @Singleton public Cache providesCache() { return new Cache(CACHE_SIZE_10_MB); } @Provides @Reusable public Api providesApi() { return new Api(TIMEOUT); } }
CACHE_SIZE_10_MB = 10 * 1024 * 1024; private static final int TIMEOUT = 20; @Provides public Presenter providesPresenter(Repository repository) { return new Presenter(repository); } @Provides @Reusable public Repository repository(Cache cache, Api api) { return new Repository(cache, api); } @Provides @Singleton public Cache providesCache() { return new Cache(CACHE_SIZE_10_MB); } @Provides @Reusable public Api providesApi() { return new Api(TIMEOUT); } }
CACHE_SIZE_10_MB = 10 * 1024 * 1024; private static final int TIMEOUT = 20; @Provides public Presenter providesPresenter(Repository repository) { return new Presenter(repository); } @Provides @Reusable public Repository repository(Cache cache, Api api) { return new Repository(cache, api); } @Provides @Singleton public Cache providesCache() { return new Cache(CACHE_SIZE_10_MB); } @Provides @Reusable public Api providesApi() { return new Api(TIMEOUT); } }
CACHE_SIZE_10_MB = 10 * 1024 * 1024; private static final int TIMEOUT = 20; @Provides public Presenter providesPresenter(Repository repository) { return new Presenter(repository); } @Provides @Reusable public Repository repository(Cache cache, Api api) { return new Repository(cache, api); } @Provides @Singleton public Cache providesCache() { return new Cache(CACHE_SIZE_10_MB); } @Provides @Reusable public Api providesApi() { return new Api(TIMEOUT); } }
CACHE_SIZE_10_MB = 10 * 1024 * 1024; private static final int TIMEOUT = 20; @Provides public Presenter providesPresenter(Repository repository) { return new Presenter(repository); } @Provides @Reusable public Repository repository(Cache cache, Api api) { return new Repository(cache, api); } @Provides @Singleton public Cache providesCache() { return new Cache(CACHE_SIZE_10_MB); } @Provides @Reusable public Api providesApi() { return new Api(TIMEOUT); } }
CACHE_SIZE_10_MB = 10 * 1024 * 1024; private static final int TIMEOUT = 20; @Provides public Presenter providesPresenter(Repository repository) { return new Presenter(repository); } @Provides @Reusable public Repository repository(Cache cache, Api api) { return new Repository(cache, api); } @Provides @Singleton public Cache providesCache() { return new Cache(CACHE_SIZE_10_MB); } @Provides @Reusable public Api providesApi() { return new Api(TIMEOUT); } }
cj. 2121 Centro – (21) 2240-2030 São Paulo - Av. Nações Unidas, 11.541 3º andar - Brooklin - (11) 4119-0449 We help companies create successful digital products