DanielBeato / GESPRO_PracticaGestionTareas_1718

0 stars 0 forks source link

Investigar inyección de dependencias con Dagger 2 #43

Closed jorgenavarroglez closed 7 years ago

jorgenavarroglez commented 7 years ago

La inyección de dependencias se implementará mediante los build flavors que proporciona gradle. No se necesitan las características avanzadas que provee Dagger 2 y por lo tanto es inútil añadir una dependencia más.

Más info sobre build flavors:

Lightweight class injection using build flavors:

For testing it is often necessary to inject stub or mocked classes into other components to emulate and test certain functionality hermetically. For example, later in our tests we will override some functionality in the notes repository to emulate the saving and loading of notes. The class Injection returns an implementation of this repository.

We have two implementations in the source tree:

-In the prod build flavor the class returns an implementation that simulates network latency. (See NotesServiceApiImpl.java). -In the mock build flavor the class returns an implementation that stubs out the service layer completely and returns a fake dataset, which can even be configured in the test (See FakeNotesServiceApiImpl.java).

These two build flavors are automatically recognised by gradle and are built directly as part of the usual debug build: prodDebug, mockDebug.

More complicated setups can use Dependency Injection frameworks like Dagger2.