Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Who is responsible for loading data?

Tags:

c#

mvvm

wpf

I have a constructor signature that looks like this.

public LocateEditorViewModel(
    ILocateRepository locateRepository, 
    int id, 
    IInteractionService interactionService)
{

As the class name suggests this is the view model I use to edit locates. This view model is created from a factory that injects ILocateRepository and IInteractionService. The id is passed in the factories Create(int id) function.

Is it the job of the LocateEditorViewModel to receive and id of the item I wish to edit and query it from the database. Or should I query for the given item in my factory and replace my int id parameter into a LocateViewModel object?

like image 573
gcso Avatar asked Apr 23 '26 13:04

gcso


1 Answers

The ViewModel works on the data of the Model which in turn accesses the database. The ViewModel does not access the database.
So: Yes, you should replace the id with the actual object.

like image 138
Daniel Hilgarth Avatar answered Apr 26 '26 01:04

Daniel Hilgarth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!