views:

102

answers:

1

I've got a number of modules in a Prism application which load data that takes 3-8 seconds to get from a service.

I would like to be able to say in my bootstrapper something like this:

PSEUDO-CODE:

Customers allCustomers = Preloader(Models.GetAllCustomers);

And this would run in a background thread and when the user actually needs the variable "allCustomers" it would be fully loaded.

Is there an automatic service in Prism/Unity which does this type of preloading?

+1  A: 

No, there is not.

However...

What you can consider is adding your ViewModel with a ContainerControlledLifetime to the container in your ConfigureContainer method that the views can use. You'd kickoff your threaded request in the constructor of your ViewModel and allow Views to pull this ViewModel out of the Container.

Even if they grab the ViewModel out of the container before the GetAllCustomers method is done firing, they will be notified correctly if the property you store the customers in implements INotifyPropertyChanged correctly.

If it was more appropriate, you could also do this from the Modules (in the Initialize method), rather than in the bootstrapper (for instance, if your Module was what actually knew about your Customer's Model).

Anderson Imes

related questions