-1

I'm using ViewModelFactory to pass API method input parameters to my ViewModel Class as someone told HERE, but my question is what should I do to send parameters of more than one API method to ViewModel?

Is it OK to call more than one API method in a ViewModel or I should create a ViewModel for every API Method?

Alireza Noorali
  • 3,129
  • 2
  • 33
  • 80

1 Answers1

0

my question is what should I do to send parameters of more than one API method to ViewModel?

It would make more sense to use dependency injection. (Dagger Hilt - ViewModel)

Is it OK to call more than one API method in a ViewModel or I should create a ViewModel for every API Method?

I recommend using Repository Pattern.

Arda Kazancı
  • 8,341
  • 4
  • 28
  • 50
  • I have Repository, now. I save data to database using Room ORM, but I should tell repository that I need to `getSomething()`, give me from db or API. – Alireza Noorali Apr 12 '21 at 11:35
  • 1
    Yes. By creating a new function, you can continue api service operations from here. The point you need to pay attention to. You add the relevant dependencies. – Arda Kazancı Apr 12 '21 at 11:45
  • about passing parametrers... is there any solution without using di? – Alireza Noorali Apr 12 '21 at 11:51
  • `is there any solution without using di?` of course, using a dependency injection framework or any library won't do something you can't do yourself – a_local_nobody Apr 12 '21 at 12:17