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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:43:01+00:00 2026-05-23T13:43:01+00:00

I am currently trying to learn how to implement MVVM using Unity and Caliburn

  • 0

I am currently trying to learn how to implement MVVM using Unity and Caliburn Micro. After looking around for help elsewhere I am still unsure about how to set up the Constructor Injection properly. I don’t know if this is not working due to my lack of expertise in MVVM or something else.

My problem is I want to pass in two IScreen Objects into my main window(shell) Class that can be navigated between when the user clicks on a button. Here is the code for the constructor in my MainWindowViewModel class:

private IScreen campaignViewModel, stringsViewModel;
public MainWindowViewModel(IScreen campaignViewModel, IScreen stringsViewModel)
{
    this.campaignViewModel = campaignViewModel;
    this.stringsViewModel = stringsViewModel;
    ActiveItem = this.campaignViewModel;
}

This is the code I am using in my Bootstrapper(Unity) class:

    private static IUnityContainer BuildContainer()
    {
        IUnityContainer result = new UnityContainer();
        result
            .RegisterInstance(result)
            .RegisterInstance<IWindowManager>(new WindowManager())
            .RegisterInstance<IEventAggregator>(new EventAggregator());

        result
            .RegisterType<IScreen, CampaignsViewModel>()
            .RegisterType<IScreen, StringsViewModel>()
            .RegisterType<MainWindowViewModel>(new InjectionConstructor(typeof(IScreen), typeof(IScreen)));

        return result;
    }

    protected override object GetInstance(Type service, string key)
    {
        var result = unity.Resolve(service, key);

        if (result == null)
            throw new Exception(string.Format("Could not locate any instance of contract {0}", service));
        return result;
    }

When this runs the MainWindowViewModel receives two instances of StringsViewModel. Although if I were to put a key into the statement:

result.RegisterType<IScreen, StringsViewModel>("StringsView");

Then it passes in two instances of CampaignsViewModel. I don’t know how to specify to the InjectionConstructor that I want it to pass in one instance of CampaignViewModel and StringsViewModel. I have a feeling it may have something to do with the GetInstance method, but I am unsure.

Any help would be greatly appreciated!

Thanks.

  • 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-05-23T13:43:01+00:00Added an answer on May 23, 2026 at 1:43 pm

    In your constructor you define the same interface twice.

    How will the DI framework know which is which?? Answer: it can’t.

    So instead of this use 2 interfaces:

     public MainWindowViewModel(ICampaignScreen campaignViewModel, IStringsScreen stringsViewModel)
    

    You can make both of these inherit from IScreen:

     public interface ICampaignScreen : IScreen
    

    and neither need add anything to IScreen – they simply provide a means for the Framework to differentiate between them.

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

Sidebar

Related Questions

I am trying to learn how to implement Web Services using Axis2 and Tomcat,
I'm currently trying to learn some Prolog (using ECLiPSe). From time to time I
I am currently trying to learn all new features of C#3.0. I have found
I am currently trying to learn C and I have come to a problem
I am currently trying to learn some more in depth stuff of file formats.
Greetings, I am currently trying to learn some Java programming. To do this I'm
While trying to learn c++, I tried to implement class representing very basic trie.
I am currently trying to learn J2ME and build a connect four game (some
I'm currently trying to learn Ruby and I'm trying to understand more about what
I'm currently trying to learn HTML and Java EE Servlet programming. I have an

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.