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

  • Home
  • SEARCH
  • 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 8747307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:20:06+00:00 2026-06-13T12:20:06+00:00

In an MVVM design, suppsoe if the View creates the ViewModel, how should the

  • 0

In an MVVM design, suppsoe if the View creates the ViewModel, how should the ViewModel know about its Model?

I read from a few places that the Model can be passed into ViewModel through its constructor. So it looks something like:

class ViewModel {
   private Model _model;
   public ViewModel(Model model) {
      _model = model;
   }
}

Since the View is creating the ViewModel, and to pass the Model into the ViewModel’s constructor, then the View has to know about the Model. But from the UML diagrams that I see from most MVVM designs, the View doesn’t seem to know anything about the Model.

How should a Model get passed into the ViewModel?

  • 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-13T12:20:07+00:00Added an answer on June 13, 2026 at 12:20 pm

    You are almost on the right track, you are just missing a crucial piece of information.

    Yes, a model can be passed to a viewmodel on the constructor – this is known as dependency injection, or alternatively as Inversion of Control (IoC).

    The absolutely easiest way to achieve this is to use the UnityContainer from Prism. Somewhere around the startup of your application you register interfaces and their corresponding implementing type with the unity container, from then on you call Resolve<MyInterface>() on the Unity container to get a physical instance of the type associated with that instance.

    Where Unity will really help you out is that it will automatically resolve as many constructor parameters as it possibly can when you tell it to resolve a type. So if your constructor on your viewmodel looks like this:

    public class MyViewModel : IMyViewModel
    {
        public MyViewModel(IUnityContainer container, IMyModel model)
        {
            _container = container;
            _model = model;
            ...etc...
        }
    }
    

    and your view does this:

    this.DataContext = container.Resolve<IMyViewModel>();
    

    the unity container will then new up an instance of the MyViewModel class, as it does that it will also resolve and new up an instance of the class associated with IMyModel.

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

Sidebar

Related Questions

In MVVM pattern I don't want to think about the view while creating the
from the design point of view, I have a complex GUI, what is the
I'm using C# WPF following the MVVM design pattern. Currently my View has a
I'm trying to implement IView for MVVM design pattern, which allows ViewModel to interact
I'm wondering if in MVVM I should design Converters and Commands be closer to
I'm using MVVM Light and Prism with the view model locator pattern. I really
I think I have a pretty good understanding of the MVVM design model, however
What is the basic definition of the Model, View and ViewModel objects in WPF's
i am using the MVVM design pattern and do not want much code in
I'm trying to understand the basic MVVM design approach, but I dont' understand where

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.