inversion of control - Prism 4.0 : Overriding InitializeShell() Method -


i've been going through documentation creating prism applications , setting shell seems split 2 methods, createshell() , initializeshell()

for createshell have:

    protected override dependencyobject createshell()     {         return servicelocator.current.getinstance<shell>();     } 

the documentation says code needed in intializeshell() method ensure ready displayed. following given example:

    protected override void initializeshell()     {         application.current.mainwindow = (window)this.shell;         application.current.mainwindow.show();     } 

i have noticed if omit first line , call show() method seems work (mainwindow appears have shell assigned it). can tell me why case, , why still need explicity set mainwindow property here?

also did not register shell interface within container, how able resolve shell in createshell()?

question 1: why calling show() seem work , why application.current.mainwindow seem populated?

there few things should check here. in typical wpf application, type main window can specified in app.xaml. if specified, wpf instantiate 1 of you. not desirable because wpf won't use container instantiate shell , dependencies won't resolved.

when run first line of code in initializeshell, you'd replacing wpf-instantiated shell object 1 manually instantiated.

i looked @ code mef , unity bootstrappers , don't see anywhere mainwindow being set, don't know if might have customized base bootstrappers, that's else for.

show() works because showing window instantiated , wpf-instantiated 1 isn't shown. theory, without seeing code, it'd tough sure.

question 2: how can unity resolve hasn't been registered?

unity can resolve concrete type, regardless of registration. cannot resolve non-concrete classes haven't been mapped concrete type. why resolve<shell> works, resolve<imyinterface> doesn't unless register type.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -