Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9078741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:42:02+00:00 2026-06-16T19:42:02+00:00

While working on a LOB desktop application with a lot of CRUD operations using

  • 0

While working on a LOB desktop application with a lot of CRUD operations using PRISM and Enterprise Library, I have noticed a recurring pattern that seems annoying. For every domain model entity (eg. Contact) I find my self wrapping it with a view model (eg. ContactVM) then I introduce a new ContactsVM (notice the ‘s’) where the latter class accepts a repository interface which is used to populate an ObservableCollection<ContactVM> and for every Contact entity that I read from the repository, I wrap it in a ContactVM which I pass the entity to via the constructor along with other enterprise library services needed by my ViewModel.

The problem is that all my view model constructors started taking this pattern like this:

ViewModel(EntityToWrap e, DependencyFromEntLib, OtherDependencies ...)

Now that is a problem because most tools and libraries require a default parameterless constructor (eg. some commercial data grids need that to provide filtering support), plus you can’t use design data to visualize entities because they need parameterless constructors too. and finally the question: What is the right way to build view models and should Entlib services be provided via constructors or via the ServiceLocator ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:42:03+00:00Added an answer on June 16, 2026 at 7:42 pm

    The following is one of many different ways to approach the problem.

    I prefer view models which are much more lightweight. I then add a class whose responsibility is to compose the view model from one or more sources (e.g. a repository). This doesn’t eliminate the problem of cascading dependencies, but it does free up your view model constructors.

    It also keeps logic out of the controllers, and allows view models to be reused (when appropriate, of course).

    • Lightweight view models

    • Lightweight controller knows how to locate a composer which assembles the view model (you could use a DI framework to setup the composer with all of its dependencies). The controller may play a minor role in the setup process, but it should be kept simple.

    • Controller knows how the view model should be assembled, and shares that with the composer class. For example, the action might request a summary view which can still leverage the same view model with no children populated.

    • Composer assembles the necessary information to complete the view model. Composer may use other composers to gather information for which it is not directly responsible. Again, a DI framework can be used here so that these composers are also given the dependencies that they need.

    • Controller renders the view as usual with the completed view model.

    In my opinion, this also provides a better level of abstraction. Just because a view model often looks like a particular domain model, that doesn’t mean it will always be the case.

    The end result:

    • Lots of classes (a downside, granted), but minimal repetition of code (i.e. DRY)

    • Thin view models which are testable (if needed…they may contain nothing to test)

    • Thin, testable controllers.

    • Testable composer objects which can be reused for different scenarios because they (presumably) know how to assemble view model(s) for various purposes.

    • Flexibility to mix and match view models, controllers, and composers to support different scenarios.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While working on ASP.NET MVC3 application, by mistake I have added a Class library
While working with ASP.NET MVC, I have noticed that exception messages issued by the
While working with ASP.NET using Visual Studio (2008) I have discomfort issue: source code
While working on something non-development related, I noticed something interested while on answers.com .
While working a project tonight, I ended up using one .js resource file for
While working with a static C++ library for my iOS Xcode project, I met
While working with the sockets library in python 2.7, I am encountering an issue
while working with WF 4.0 I noticed that the WorkflowApplication class exposes action properties
While working on a larger project, a few lines of code using java.net.Socket failed
While working with JSF in order to develop web applications using NetBeans, I many

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.