Prism/Unity 是否有“服务预加载器”?
我的 Prism 应用程序中有许多模块,它们加载需要 3-8 秒才能从服务获取的数据。
我希望能够在我的引导程序中说这样的话:
PSEUDO-CODE:
Customers allCustomers = Preloader(Models.GetAllCustomers);
这将在后台线程中运行,并且当用户实际上需要变量“allCustomers”,它将被完全加载。
Prism/Unity 中是否有自动服务可以进行此类预加载?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,那里没有。
但是...
您可以考虑将具有 ContainerControlledLifetime 的 ViewModel 添加到视图可以使用的 ConfigureContainer 方法中的容器中。 您可以在 ViewModel 的构造函数中启动线程请求,并允许视图将此 ViewModel 从容器中拉出。
即使他们在 GetAllCustomers 方法完成触发之前从容器中获取 ViewModel,如果您存储客户的属性正确实现了 INotifyPropertyChanged,他们也会收到正确的通知。
如果更合适,您也可以从模块(在初始化方法中)而不是在引导程序中执行此操作(例如,如果您的模块实际上了解您的客户模型)。
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).