Uma introdução abordada com códigos de exemplo para demonstrar a necessidade e como utilizar da forma mais simples possível o framework de injeção de dependência "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 Ajudamos empresas a criar produtos digitais de sucesso