我应该使用单身人士来阅读应用配置设置吗? [英] Should I use a singleton to read app config settings?

查看:62
本文介绍了我应该使用单身人士来阅读应用配置设置吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从.config文件管理器加载应用程序设置并创建名称 - >对象图(概念上类似于EF创建模型的方式)。



我是否应该使用单例并在需要地图的任何实例之间共享它,或者实现此目的的最佳方式是什么?



我是什么尝试过:



在线寻找想法但未找到明确的是/否所以需要想法

I need to load application settings from a .config filer and create a name->object map (conceptually similar to how EF creates the model).

Should I do this with a singleton and share it around between any instances that need the map, or what is the best way to implement this?

What I have tried:

Looking for ideas online but not found a definitive yes/no so need thoughts

推荐答案

首先,请阅读我对该问题的评论。由于许多因素可能会影响单身人士,我担心没有人能够明确地说'是'或'不'使用单身人士......注意,之前有人问过类似的问题:设计模式:何时使用Singleton? - 堆栈溢出 [ ^ ]并没有明确的答案!



如MSDN所述:

First of all, please read my comment to the question. I'm afraid that no one is able to definitively say 'yes' or 'no' for use of singleton due to many factors may affect on that... Note, that someone asked similar question before: On Design Patterns: When to use the Singleton? - Stack Overflow[^] and there's no clear answer!

As MSDN states:
上下文

在某些情况下,某些类型的数据需要可供应用程序中的所有其他对象使用。在大多数情况下,此类数据在系统中也是唯一的。例如,用户界面只能有一个所有应用程序必须访问的鼠标指针。同样,企业解决方案可以与管理与特定遗留系统的连接的单网关对象接口。

In some situations, a certain type of data needs to be available to all other objects in the application. In most cases, this type of data is also unique in the system. For example, a user interface can have only one mouse pointer that all applications must access. Likewise, an enterprise solution may interface with a single-gateway object that manages the connection to a specific legacy system.





请参阅:

Singleton [ ^ ]

在C#中实施Singleton [ ^ ]


这篇关于我应该使用单身人士来阅读应用配置设置吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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