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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:48:47+00:00 2026-06-11T16:48:47+00:00

I have class two ViewModels //both IViewModel1 and IViewModel2 inherit from IViewModel public class

  • 0

I have class two ViewModels

//both IViewModel1 and IViewModel2 inherit from IViewModel
public class ViewModel1 : IViewModel1
{}
//and
public class ViewModel2 : IViewModel2
{}

and the view :

public partial class View : UserControl
{
View(IViewModel)
{}
}

How can I do to inject one of the ViewModels into the View using Unity container ?
Edit : My issue is on having choice to inject one of the view models from the constructor.

  • 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-11T16:48:48+00:00Added an answer on June 11, 2026 at 4:48 pm

    If you use Unity to resolve your view and the IViewModel is part of the signature of the constructor then Unity will resolve it for you (provided you have already registered it, for example in the loading of a module):

    public View(IViewModel1 vm)
    {
        InitializeComponent();
        _myViewModel = vm;
    }
    

    Keep in mind that Unity is greedy – it will try to resolve the biggest constructor it can so if you want to select a particular constructor for it to use then you will need to use ParameterOverrides.

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

Sidebar

Related Questions

I have three ViewModels: QuestionViewModel Theese two inherit from QuestionViewModel MCQViewModel MatrixViewModel I send
I have two ViewModels: public class CommandViewModel { public string DisplayName { get; set;
I have a class with two constructors (C#). Here is the code snippet: public
I have a class with two constructors that look like this: public MyClass(SomeOtherClass source)
Given I have a class with two constructors: public class TestClass { ObjectOne o1;
I have a main class and two extended classes: class Main { public $foo;
I have an example class containing two data points: public enum Sort { First,
So I have this two classes: public class PhysicalTest { public int ID {
I have a ViewModel that contains two objects: public class LookUpViewModel { public Searchable
I have a situation where I need to see if two viewmodels derive from

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.