MVVM的ViewModels辛格尔顿 [英] MVVM ViewModels Singleton

查看:126
本文介绍了MVVM的ViewModels辛格尔顿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一种错误的做法,使所有的ViewModels单身,如果你不需要每个屏幕的多个实例?

Is it a wrong practice to make all viewModels singleton if you don't need multiple instances of each screen?

推荐答案

是的,因为的单身是邪恶的

您可能会碰到那里的虚拟机都抱着到状态,这可能是与你的数据库不同步而导致内存消耗过大的问题。 这将是更难单元测试,由于国家正在持续。

You will probably run into issues where the VMs are holding onto state which could be out of sync with your database and lead to excessive memory consumption. It will be much harder to unit test due to the state being persisted.

这篇关于MVVM的ViewModels辛格尔顿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆