Answer the question
In order to leave comments, you need to log in
How to organize architecture when using C#, WPF, MVVM?
Hello. Sorry for war and peace. I don't know how to briefly ask about architecture.
I often have problems with misunderstanding how it is possible / necessary to build interaction between different parts of the application. Let's say we have:
1. BackgroundWorker - some kind of background service (device, parsing bot, etc.).
2. StorageService - data storage layer (sql, nosql, serialization).
3.UI - wpf, mvvm.
Now I will describe how I usually do it and what I think about it.
1. BackgroundWorker - I create a separate classlibrary where I put everything related to this worker. I create independent data models (POCO, no gui's IPropertyChanged, etc.), add events using these models. That is, api is built on the principle of calling a method for control, an event for informing in the opposite direction. I build it as independent as possible, so that if something happens, it can be used in various external conditions (console, gui, service).
2. StorageService - just like in the previous case, I am building the most independent solution. All models describe strictly the data layer, no left properties / methods, again POCO. I usually use Unite of Work/Repository for a large solution, or one class (DbService) to work with all entities for a small solution. I don't like ActiveRecord.
3. Ui - this is where my problems begin. Since to display all this you have to fence a bunch, as it seems to me, crutches. For example, I will describe the latest development for the house. Wrote a bot for taking honey. coupon. All three layers have their own
class Job //Общий класс описывающий задание
{
Guid PersonId {get;set;}
bool Enabled {get;set;}
List<Period> Periods{get;}
//Другие поля
}
class Period //Информация когда брать талончик
{
//Другие поля
}
class Person //Человек для кого берем
{
Guid Id{get;set;}
//Другие поля
}
PeopleService {public ObservableCollection<Person>{get;set;}}
and inject it into the PeopleViewModel and each JobViewModel. Or throw an ObservableCollection from the PeopleViewModel only into the JobsViewModel and from there slip each JobViewModel (but less connected) Answer the question
In order to leave comments, you need to log in
Have you read about PRIMS yet?
If you want in Russian: https://habrahabr.ru/post/176851 If you
want in the original language: MSDN.
Also, if you haven't read about RX (Reactive Extensions) yet, it's time.
All together will give you a complete set for building a UI of any complexity.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question