Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm fairly new to the MVVM concept but like a lot of the flexibility it gives me so far. However, I'm struggling to find a good way to manage my code. I have several classes that are just sitting in a folder in my solution such as xxxView.cs, xxxViewModel.cs, yyyView.cs, yyyViewModel.cs, zzzView.cs, zzzViewModel.cs you get the idea. It has started to crowd my solution, making it harder to find the files I'm looking for. Is there some standard way to organize these files? Do I create a View and ViewModel folder to separate and clean up the solution or have people found a better way?

share|improve this question
2  
Microsoft has a reference implementation here that you can study. – Robert Harvey Jan 8 at 21:47
@RobertHarvey Thanks! That will work well for our solution structure. – lumberjack4 Jan 8 at 23:09

2 Answers

up vote 1 down vote accepted

We use separate projects for

  • View
  • ViewModel
  • Model

And within those projects, we'll potentially add folders to provide additional structure.

The View project references ViewModel, and the ViewModel project references the Model.

Images often receive their own folder. So far, resource dictionaries, converters, and extended objects have been placed in the main project folder for the layer.


An alternative is to have "major application areas" as projects. Then you have either have V / VM / M folders within each area or you just place the related MVVM files in the area project folder.

I don't like this approach as much since I'll frequently have to work on multiple Views at a time so I end up navigating through a lot more project structure than I would like.

This approach kind of limits re-use when it comes to resource dictionaries or similar. The cross-referencing of projects can become difficult to maintain. However, creating a dedicated "common resource" project would be an approach to easing this problem.

share|improve this answer
We use the Application Areas structuring, so it seems, in my case, it would be best to create the View, ViewModel, and Model folders where appropriate. – lumberjack4 Jan 8 at 23:12

If you don't want separate projects, at least separate the different parts with project folders and namespaces.

I use a different pattern. I keep related view, viewmodel, and model in the same assembly, separated by namespace. Each new relationship creates a new assembly.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.