Click here to Skip to main content
15,880,725 members

.net MVVM application and design-time data

koleraba asked:

Open original thread
Hi
I have a more theoretical than a "hands on" question regarding the "design-time" data for WPF applicatons which use the MVVM pattern.

Lately I use two kinds of view-models in my applications. The "runtime" view-models which are used at runtime and "design-time" view-models which are used at design-time(when the designer is designing the views in expression blend). Everything I read about this topic suggests that the design-time view-models should be located in a different assembly so you don't have to ship them with the application. And therein lies my problem. Let's say I have two assemblies: Assembly XYZ.ViewModel(containing the runtime view-models) and XYZ.Design(containing the design-time view models). Since I oftenly use IOC containers both the design-time and runtime view-model for the same view must implement some shared interface. So in which assembly should I put the interfaces? If I put them in the XYZ.Design assembly than the XYZ.ViewModel must reference that assembly and I have to ship it with the appliation. I tried to put the interfaces in the XYZ.ViewModel assembly but that would create circual dependency becouse the XYZ.ViewModel assembly must reference the XYZ.Design assembly for the design-time view-models and the XYZ.Design assembly has to reference the XYZ.ViewModel assembly becouse of the interfaces.

The only solution to this problem seems to be to create the third assembly XYZ.Interfaces and put all the interfaces in that assembly. This approach works If I use the IoC container to assign the design-time view-model to the view or if I use the following expression in the view.
HTML
d:DataContext{d:DesignInstance, Type=design:SomeType, IsDesignTimeCreateble=True}


But it seems to me that creating a separate assembly just to contain the view-model interfaces is to much. If you have multiple aseemblies containing view-models(let's say for different applicaton moduls) than you end up with three assemblies for each one.
So my question is: Has anybody found a better or different approach to deal with this problem? Any thoughts on the subject will be appreciated.

Uroš
Tags: .NET (.NET4.5), WPF, MVVM

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900