1
    protected override Window CreateShell()
    {
        return Container.Resolve<MainWindow>();
    }

referring to the above code in Prism/blob/master/Sandbox/Wpf/HelloWorld/HelloWorld/App.xaml.cs, I do not understand how the MainWindow type is registered with the container.

looking at the registrations of the container, MainWindow type is not listed. enter image description here

Can someone please help me to understand how it works?

Cœur
  • 37,241
  • 25
  • 195
  • 267
leon
  • 35
  • 4

1 Answers1

0

I do not understand how the MainWindow type is registered with the container

It is not registered with the container. Unity by default resolves concrete types transiently. You only have to register a concrete type if you want it to have a non-standard lifetime, e.g. a singleton.

Haukinger
  • 10,420
  • 2
  • 15
  • 28
  • why is type MainWindow visible to Unity container? It uses Reflection? – leon Feb 05 '20 at 09:11
  • Not sure what you mean by _visible_, but calling a method with a type parameter for sure _makes the type known to the method_. Internally, Unity uses reflection, not only `Activator.CreateInstance`, but also looking for attributes and so on. Note that this is no different from types that _are_ registered (unless you pass a factory method with the registration, in which case there's no need for `Activator.CreateInstance`). – Haukinger Feb 05 '20 at 10:12