Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to organize interfaces and implementations in WPF MVVM application

I'm working on WPF MVVM project which contains following projects,

  • Domain,
  • ViewModels,
  • Infrastructure,
  • Views

and for example I need IFileService that provide some operations with file and doesn't contains any business logic, I'm sure that the implementation of this interface FileService will be in Infrastructure project, but I have question where to put the IFileService interface

I need to use this interface in ViewModels project, if I will put it in this projects its mean that Infrastructure will have reference on ViewModels that is not good I think, if I will put it in Domain which contains business related classes the same.

Help me what is the best to organize structure and references between projects and where to put interfaces like IFileService?

like image 892
Serghei Avatar asked Mar 22 '13 10:03

Serghei


2 Answers

Hmm, why not creating an additional project like DAL or DataLayer? It provides the model classes, which I'm also missing in your listing. You could also put the interface IFileService there although I would prefer working with DataProviders or Repositories (that's my prefered option), so that the VMs are not aware from where the data was loaded.

IMHO The project Infrastructure shouldn't not contain any sofisticated logic. I would put some useful methods and classes there and keep it as simple and clean as possible, so that it could be referenced everywhere. Probably, you won't even need it.

like image 73
DHN Avatar answered Sep 17 '22 12:09

DHN


The unique rule I use for my MVVM project is, all projects have a reference to my Infrastructure project and my Infrastructure project has no reference to my other project.

So IMHO, IFileService, and interfaces in general, should be in the Infrastructure project. Then it is up to you decide where to put the implementation. The Infrastructure project usually has very basic logic implementation and final implementation goes to a dedicated project.

The only exception I sometimes add to this rule is when I base my development on an existing MVVM framework, then Infrastructure might reference it too but I try to avoid this approach.

like image 31
Ucodia Avatar answered Sep 17 '22 12:09

Ucodia