How to organize interfaces and implementations in a WPF MVVM application

I am working on an MVVM WPF project which contains the following projects,

  • Domain
  • ViewModels,
  • Infrastructure,
  • representation

and, for example, I need IFileService , which provide some file operations and do not contain any business logic, I am sure that the implementation of this FileService interface will be in the infrastructure project, but I have a question where to put the IFileService interface

I need to use this interface in the ViewModels project, if I put it in these projects, this means that the Infrastructure will refer to ViewModels, which is not very good, I think if I put it in a Domain that contains classes related to business, same.

Help me, what is the best way to organize the structure and links between projects and where to place interfaces such as IFileService ?

+7
source share
3 answers

Hmm, why not create an additional project like DAL or DataLayer ? It provides model classes that I also miss on your list. You could also host the IFileService interface IFileService , although I would prefer to work with DataProviders or Repositories (this is my preferred option) so that the virtual machines do not know where the data was downloaded from.

IMHO The Infrastructure project should not contain any complex logic. I would put some useful methods and classes there and keep them as simple and clean as possible so that you can refer everywhere. You may not even need this.

+4
source

The only rule that I use for my MVVM project is that all projects have a link for my infrastructure project, and my infrastructure project does not have a link for my other project.

So, IMHO, IFileService and interfaces in general should be in the Infrastructure project. Then you decide where to put the implementation. An infrastructure project usually has a very basic logical implementation, and the final implementation goes to a dedicated project.

The only exception that I sometimes add to this rule is when I base my development on the existing MVVM infrastructure, then the infrastructure can also refer to it, but I try to avoid this approach.

+3
source

You must put the IFileService interface in the infrastructure project. because it will make it available for every project, as this is the basic right of the project. and you may have different implementations, for example. syncronious file reader and asyncronius file reader. therefore, an implementation can go into your modules or ViewModels.

+1
source

All Articles