Click here to Skip to main content
15,887,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 22-Sep-16 9:10am
Comments
David_Wimbley 22-Sep-16 9:24am    
What is wrong with ConfigurationManager.AppSettings[] method?
Duncan Edwards Jones 22-Sep-16 10:36am    
Nothing but I am doing a lot of post-processing of the settings which I don't want to have to do multiple times (wiring up delegates &c.)
Maciej Los 22-Sep-16 12:11pm    
Not sure what kind of issue do you have...
As per my knowledge a singleton is used for such of functionality...
[no name] 22-Sep-16 15:56pm    
I have done this before and it worked out pretty well for my application.

1 solution

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:
Context
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.


See:
Singleton[^]
Implementing Singleton in C#[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900