WPF - Where to host DAL in a three-tier architecture with MVVM?

I am new to the whole architecture of n-tier architecture, and I had some questions about using MVVM with a three-tier application.

In my opinion, we have:

  • Presentation Level or UI, which is a xaml file
  • A model, which is a custom class that contains properties and methods that "model" a data object.
  • ViewModel, which is the "adapter" between the view and the model
  • A WCF server that should handle database access by the way.
  • SQL database for data storage

My question is: how can I put all this together using the data access layer? With MVVM, I would have models containing load / update methods. Instead, should it be something that happens on the WCF server? If so, should the link to the server be stored in the model or in the ViewModel? And what should it be called?

+5
source share
3 answers

Strictly, DAL is not part of the MVVM pattern. DAL is the back model, and the view and view model should not know anything about DAL.

For example, expose objects as properties of your model, which are loaded upon first access.

public class ProductListModel
{
    public List<Product> AllProducts 
    {
       get
       { 
          if (_AllProducts == null)
              _AllProducts = MyServiceProxy.LoadAllProducts(...)  
          return _AllProducts;
       }
    }

    public void SaveChanges()
    {
         if (_AllProducts != null)
           MyServiceProxy.SaveProducts(AllProducts);
    }
} 
+8
source

- ... , - , MVVM.
WCF , , , , , cxase , ...
( , , WCF...

0

All Articles