views:

149

answers:

1

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?

+1  A: 

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.

Robert Harvey
It creates the bigger problem of the server dying and the information never being saved to the database, if that call is made in the application end or dispose methods.
Yuriy Faktorovich
from what i understand, nhibernate retains the cache only for the current session. so i will still be hitting the db unnecessarily for each session.anyway, so i create a class IdentityInfo with fields ID, FieldName and maybe FieldValue. Then i have nhibernate populate a List<IdentityInfo> for all possible identity fields for each client. Use this to have nhibernate then fetch the actual values that identify the user... is that the best solution? because am confused simply by typing that :)
Amith George
@Yuriy: Information like this is only occasionally changed, so you perform a save every time you change it. You only cache the reads.
Robert Harvey
@strider: Yes, that is essentially how you would do it.
Robert Harvey