Prism/Unity 是否有“服务预加载器”?

发布于 2024-07-29 12:32:27 字数 361 浏览 0 评论 0原文

我的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疏忽 2024-08-05 12:32:27

不,那里没有。

但是...

您可以考虑将具有 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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文