How does IDialogManager in Hello Screens work?

Topics: Bootstrappers & IoC, Conventions, Getting Started
Oct 26, 2012 at 10:36 PM

I've been pouring over the Hello Screens sample and am curious how an IDialogManager is passed to the ShellViewModel?

 [ImportingConstructor]
        public ShellViewModel(IDialogManager dialogs, [ImportMany]IEnumerable<IWorkspace> workspaces) {
            this.dialogs = dialogs;
            Items.AddRange(workspaces);
            CloseStrategy = new ApplicationCloseStrategy();
        }

Is MEF supplying the DialogCOnductorViewModel, or is CM doing that through one of its conventions? 

The answer to that may also answer this followup question:

If I remove the DialogConductorViewModel class from the project and run it, it throws an error that it cannot find an IShell class.  Why...?

Oct 26, 2012 at 10:45 PM

I think i just figured it out (it always happens after posting a question).

Whenever MEF encounters an ImportingConstructor, each of the parameters become imports.   A reference I found is here.

What threw me was that one of the parameters had an import declaration and the other did not.  But the [ImportMany] is necessary to override the default of [Import].