T
T
Tsuzukeru2021-03-26 21:38:55
Android
Tsuzukeru, 2021-03-26 21:38:55

Do I need to do DI for simple Kotlin objects?

There is an Rx method inside which I do some transformation of the response from the server using kotlin
object - RawMediaPreviewResponseConverter .

...
.subscribe({
          val mediaPreviewResponse = RawMediaPreviewResponseConverter.getMediaPreviewResponse(it)
          _downloadedMediaPreviewsResponse.postValue(mediaPreviewResponse)
          _networkState.postValue(NetworkState.LOADED)
                    }
...


If I use DI (Dagger) - does this mean I need to do DI directly for all dependencies? Even for small classes like my RawMediaPreviewResponseConverter? It has only two methods and nothing else.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Zagaevsky, 2021-03-27
@Tsuzukeru

In general, yes, everything needs to be implemented. Let's give an example. Here you have some kind of media preview converter. I don't know what he does, but let's say he formats some kind of preview, photo or video, right? In this case, you may need to use the context to get the screen sizes, because the preview on different screens may have different sizes. This is where di comes in handy.

A
Alex Wells, 2021-03-26
@Alex_Wells

Well, if your converter has no dependencies, it is not open and not an interface, then you can also use object, there is no difference at all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question