I'm trying to divide my system into layers. It turns out like this: enter image description here

Just in case, I will say that I use the MVVM pattern. Although in my opinion this does not apply to the issue. Here I have 4 layers. The View layer refers to the ViewModel layer. That is, the View layer View a ViewModel client. I want the View layer classes to depend not on specific ViewModel classes, but on interfaces. Where do I publish these interfaces? The OCP principle (open / closed principle) says that the interfaces belong to clients. But if I publish the interfaces for the classes of the ViewModel layer in the View layer, it turns out that the ViewModel depends on the View .

  • Okay, why not publish the VM interfaces in the VM itself? - VladD
  • If you want V to depend only on interfaces, make the interfaces public, and designate specific implementations as internal . - VladD

2 answers 2

I apologize if I do not say that, but it seems to me that:

  • View and ViewModel would be well in one layer. Still, the ViewModel is more about presentation logic.
  • you should not replace the ViewModel with its interface, but instead it is better that ViewModel accept the interface of the service working with data in the designer. In the view of the model there is a husk (I usually have) relating to the view, for example, the flag IsBusy (data loading). Such a husk will need to be duplicated from the interface to the interface if using IViewModel , and this is not necessary.

If not DDD , but simpler, then it would be possible to have 3 layers (as an option).

  • User Interface (v, vm)
  • Application Services (repository management, logic, application service interfaces )
  • Persistence (repositories working with the database)

This is probably something close to CRUD . I accept criticism.


disclaimer: speaking from the WPF bell tower


The following scheme and everything that is written below no longer applies to the question . Simply, Monk in his response showed a diagram of dependencies of layers, it seems for DDD . I wanted to give an example of how it worked for DDD . In addition, there was already a finished diagram (of assembly dependencies). A little more complicated, and maybe about the same.

enter image description here

Used IoC . Interfaces were in the following builds:

  • in Application Service Layer - interfaces for services
  • Domain Layer - domain level interfaces

    In fact, I have never seen perfect solutions on this topic. In DDD, interfaces can be thrust into a domain layer that is accessible to everyone outside:

    DDD Layers

    If suddenly it seems to you that it does not belong to the domain layer - the interfaces obviously move to the application layer so that the UI can access them.