When to initialize properties in ViewModel

Topics: Getting Started
Jul 3, 2013 at 10:40 AM

I want to load entities from a database with EF and create a CollectionView property for the view to bind to.
Where is the best place for this code in the ViewModel (screen)? There are lot of possibilities

A) constructor - just seems wrong with too much code in a constructor
B) In the get part of the property. The property has a backing field, if the field is null I initialize it and return it. I can't have an auto property, which I like, otherwise it seems like the perfect place, initialize when needed.
C) One of the events from CM, OnActivate, OnViewLoaded

I would love to hear your opinion :-)
Jul 4, 2013 at 6:06 AM
If you want to go lazy (for performance benefits etc) how about using Lazy<T>, i.e. only when accessing you would create the view model (delayed and on demand)

Otherwise i'd go with B or C