Suppose I have a lot of UserControl , each of them has its own VM, each of which wants to work with the database. Inside each VM, creating a connection to the database seems to me to be the wrong approach. How in this case to build a good architecture?

  • Ideally, there should be a connection pool probably so that connections are created only in the absence of free ones. And you can also create a connection at the client's startup and use it everywhere, although this is not very correct. - Monk
  • Connection to the database is generally a model thing. - VladD
  • @VladD, let's say the user enters some kind of data, we considered them and want to add them to the database. How to act in this case? All UserControls have the same working principle, they just all work with different tables. - Lightness
  • Well, VM makes a call to the model, and how the model saves data is its internal matter. - VladD
  • @VladD, then inside the VM there will be a model object, and since the model is common to all. would it not be better if she were somehow taken out of the VM? - Lightness

0