0

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?

4

1 回答 1

1

不,那里没有。

然而...

您可以考虑将带有 ContainerControlledLifetime 的 ViewModel 添加到视图可以使用的 ConfigureContainer 方法中的容器中。您将在 ViewModel 的构造函数中启动线程请求,并允许 View 将此 ViewModel 拉出容器。

即使他们在 GetAllCustomers 方法完成触发之前从容器中获取 ViewModel,如果您存储客户的属性正确实现 INotifyPropertyChanged,他们也会收到正确的通知。

如果更合适,您也可以从模块(在 Initialize 方法中)而不是在引导程序中执行此操作(例如,如果您的模块实际上知道您的客户模型)。

于 2009-07-28T17:50:18.427 回答