Steven Liekens
Steven Liekens

Reputation: 14123

Which assembly does a ViewModel belong to?

I'm just learning the ropes of the MVVM pattern in WPF applications, and I can imagine that this sounds like an incredibly stupid question, but here goes anyway:

I already have a model in one assembly, which is a simple class library. In a different assembly, I've created a simple view in xaml. Now the books all tell the same: link them together with a viewmodel. My question is though, where does this viewmodel belong:

I know the MVVM pattern is merely a design guideline and not a strict set of rules, but I feel it's better to learn things the right way.

EDIT

Follow-up question: is a viewmodel meant to be re-usable? I can imagine a scenario where it would be usefull if you could use the same viewmodel for a WPF desktop application and a silverlight web application.

Upvotes: 1

Views: 262

Answers (2)

Tim Rogers
Tim Rogers

Reputation: 21713

It facilitates building the view, so it belongs in the view assembly.

Think of it like this: could you take your model assembly and use it in a different style of application, e.g. a Windows service or a web application? Is there anything that is irrelevant to that style of application in that assembly? If the answers are yes and no, you've built yourself a useful re-usable component that is independent of the type of user interface.

Upvotes: 1

Thomas Levesque
Thomas Levesque

Reputation: 292615

Depending on the size of the project, I put the ViewModels either in the same assembly as the views, or in their own assembly, but never in the model assembly. The model shouldn't contain anything related to the UI.

Upvotes: 0

Related Questions