Sample mistake

Jul 13, 2011 at 4:57 PM

In documentation 1.0 for WP7 view models are registered in this way:

        container.RegisterSingleton(typeof(MainPageViewModel), "MainPageViewModel", typeof(MainPageViewModel));
        container.RegisterSingleton(typeof(PageTwoViewModel), "PageTwoViewModel", typeof(PageTwoViewModel));
        container.RegisterPerRequest(typeof(TabViewModel), null, typeof(TabViewModel));

but in newest samples:



container.PerRequest<TabViewModel, TabViewModel>();

which is correct?

Jul 13, 2011 at 6:05 PM

It depends on which version of the framework you are using :)  The samples show v1.1. There are separate docs for v1.1

Jul 13, 2011 at 6:08 PM

So in 1.1 every view (page too?) should be registered by request? What is purpose of singleton then?

Jul 13, 2011 at 6:21 PM

Typically, you would register ViewModels for pages as per request. You might choose to register other ViewModels, services, state objects, etc as singleton. It depends on your architecture. Also, now that I am looking at it, I think that singleton registration in v1. was a mistake and should have been per-request.

Jul 13, 2011 at 6:29 PM
Edited Jul 13, 2011 at 6:33 PM

Huh i thought that view models for pages should be registered as singletons because they are main "components" and are not included in other components so they are created once for app life cycle. I'm asking this because i've some strange issue with pivot page - when its registered as singleton it doesn't bind header on some machines/devices when per request everything is fine.