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 9145347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:29:28+00:00 2026-06-17T10:29:28+00:00

Our new project started out with View first pattern using ViewModelLocator to marry the

  • 0

Our new project started out with View first pattern using ViewModelLocator to marry the view with the viewmodel.

I’d like to change to a ViewModel first pattern.

Here is my view model constructor:

public DeviceSelectionViewModel(IDataModel dataModel, IMessenger messenger)
{
    if (dataModel == null) throw new ArgumentNullException("dataModel");
    if (messenger == null) throw new ArgumentNullException("messenger");

    Selector = new PlantDataTemplateSelector();
    PlantSelector = new PlantNodesSelector();
    Plants = new List<Plant>(0);

    messenger = messenger;
    messenger.Register<PlantDataLoadedMessage>(this, m => DispatcherHelper.CheckBeginInvokeOnUI(() => OnPlantDataLoaded(m.Plants)));

    RefreshData(_dataModel);
}

Here is how I’m now selecting the appropriate ViewModel using ViewModel first.

public class MainViewModel : Module
{

    public MainViewModel()
    {
        SelectedView = new DeviceSelectionViewModel();
    }

    public ViewModelBase SelectedView { get; set; }

}

With View first, I never directly called the ViewModel via code so the Constructor Dependency Injection worked fine.

Now that I’m calling the ViewModel via a controller ViewModel, it wants the 2 parameters for the ViewModel Constructor.

Is the proper play here to hold the references in the controller view model and pass them into the constructor? I’m missing something here with how DI works in this scenario?

I’m still putting the pieces together with DI(Ninject) and MVVM, so be kind 🙂

  • 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-17T10:29:29+00:00Added an answer on June 17, 2026 at 10:29 am

    We had the same issue.

    You have the following choices:

    • MainViewModel creates DeviceViewModel providing the values for required parameters
    • MainViewModel gets already resolved DeviceViewModel

    The first variant increases coupling in case when DeviceViewModel is exposed only for View bindings. If MainViewModel communicates with DeviceViewModel then coupling is already implied unless MainViewModel sees DeviceViewModel through some interface what inevitably requires the second option.

    Another problem of the 1st approach is that in some cases nested VM can require more values for its creation as parent VM needed.
    This can be solved by extending parent VM constructor to contain these additional parameters. But when (though never in practice) building complex VM graphs root VM’s constructor can become bloated.

    We now have a mix of both options.

    All our ViewModels inherit from ViewModelBase abstract class. It has several overloaded constructors and most of them get IViewModelFactory as an input. So we can ask the factory to create ViewModel wee need. Wee decided not to worry about the returned type and just return the type of created ViewModel incapsulating only its creation. So it is not true DI.

    We also use Messanger but our ViewModels cannot send messages explicitly and can only subscribe to the messages. We did so intentionally as a way to restrict a set of messages particular VM can send (and even subscribe to).

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

Sidebar

Related Questions

We are using Linq-to-SQL with SQL Server as an ORM on our new project.
How to improve our productivity when starting new project using Delphi? For me, I
We just started a new project in Java EE in our office and i
We have just started our new assignment - web-based project. Before I get directly
I have just started a new project using a Linq to Sql model and
i want to use stripes in our new project. This will take care of
I'm investigating presentation layers to be used with spring in our new project. I'm
We are starting off a new project with sitecore as our CMS. I was
In our company we have started using VS 2010 to model our systems, in
I'm working on a new project and we're using a pretty nice stack. NHibernate,

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.