During development, we will frequently use types that are resource-intensive for construction in terms of memory or computation time. So we might want to delay the construction of these types until we actually need them. This can be achieved by a new feature introduced in .NET framework 4.0, called Lazy Initialization. We can use this feature to improve the performance of our applications by delaying the instance construction of types.
Let's look at a sample window which is part of a contrived medical application. Let's create a WPF MVVM Light project, called
MVVMAppLazyInitialization, in .NET Framework 4. In this sample, patients are selected and loaded, as shown in the following screenshot, so that their information can be viewed. As shown, some of their information can be viewed and edited. If we start loading everything in a single pass, it would take a lot of time for the window to show up, as data is fetched from persistence stores.
A patient's data might come from...