ASP.NET MVC 应用程序中的全局状态
问题:我们的 Web 控制台显示安装了我们的应用程序的所有计算机的列表。每台机器都有一些与其关联的标识信息。简单的字符串,如部门名称、团队名称等。我们需要让用户可以更改这些标识字段的名称并添加/删除任意数量的字段。我们怎样才能最好地实施这一点?
最初我认为我可以将其作为单例来实现。在应用程序启动时,我可以从数据库中读取最后设置的标识字段名称,并创建字符串列表的单例实例。这可以传递给需要显示或访问身份信息的所有功能。此选项的吸引力在于,如果用户从 ui 更改身份字段名称或添加或删除字段,我可以简单地修改单例对象,并且更改将得到反映。
但是我觉得必须有更好的方法来实现我想要的。因为这样的信息有很多,用户可以随意修改,我们需要对其进行跟踪。
有什么建议吗?
Problem: Our web console shows a list of all computers on which our application is installed. Each machine has some identification information that can be associated with it. Simple strings like department name, team name etc. We need to make it such that the user can change the name of these identification fields and add/remove as many as he wants. How can we best implement this?
Initially i thought that i could implement this as a singleton. In the application start, i could read the last set identity field names from the db and create a singleton instance of a list of strings. This could be passed around to all functions that need to display or access the identity information. The appeal in this option is that if the user changes the identity fields name from the ui or adds or removes the fields, i can simple modify the singleton object and the change will be reflected.
However i feel there must be a better way to achieve what i want. Because there a lot of such information that the user can modify at will and we need to track them.
Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需使用 ORM 中的对象即可在应用程序中维护和使用此信息。许多 ORM 都能够缓存此类内容,因此您不会因此而损失任何速度。
我不太喜欢使用 Singleton 来做到这一点。单元测试很困难,并且最终您仍然必须将其保存到数据库中。
Just use the objects from your ORM to maintain and use this information in the application. Many ORMs have the ability to cache this sort of thing, so it's not like you will lose any speed over it.
I'm not a big fan of using a Singleton to do this. It's hard to unit test, and you'll still have to persist it to the database eventually.