I've seen a couple of ideas on this. Classes that house variables. Static classes with static variables using a Singleton-like structure. What are the methods and pros/cons? I'm looking to use some site-wide variables soon, but haven't given it a go yet.
Application scope. These will be stored dictionaries, lists, and other tools used to identify mappings between SQL data and the visible representation as well as site-wide static data. I'm thinking of going with a singleton structure. It feels very smooth
and right, but I want to know the different ideas, pros, and cons out there first.
SGWellens: That's an interesting feature I didn't know about. That would work great for some of the more static database pulls I'll be doing. I think the dictionaries and such would benefit from a application level instantiation. They may not be used often,
but when they are used, I'd like them already created and sitting ready. (Although, giving it some thought cacheing with a large enough time dependency would render pretty much the same outcome for most all users).
AdamTurner34: This isn't so much data analysis as it is data pairing. For example, my SQL row headers were not created by me and do not have a user friendly form. I want a dictionary to map the SQL headers with the display text so I can fluidly grab that.
I don't want to recreate the dictionary for this on each page, so application scoped. The cacheing would work well for the xml/database data on a whole though.
This isn't so much data analysis as it is data pairing. For example, my SQL row headers were not created by me and do not have a user friendly form. I want a dictionary to map the SQL headers with the display text so I can fluidly grab that.
Hopefully I am wrong here but other than the static lists, etc (which the suggestion for Application Caching is a great one and he one I recommend as well), you are not inferring that you want some type of global dictionary mapping of SQL values to global
variables are you? I hope I am wrong here because I used to see that in VB6 where these huge monolithic modules were used to create global varibales that represented their SQL data equivilent and they were nasty. For example a SQL value of "CustomerLastName"
might be "gFld_CustomerLastName". Global scope and so easy to step on the toes of varibales because no encapsulation of behavior or data was used via individual classes.
If for some reason what I described above is indeed what you want then I strongly recommend a different approach. This is the responsibility of the data model being mapped to the object model. Typically this happens low in the lowest layers of the
application, and in return values are exposed via Properties on classes. Or use something like EF and this is doen for you already. Weather a busniess object, DTO, or something else, the values are never just represented by some gloal variable with no relationship
to anything else all on its own.
steventnorri...
Member
11 Points
14 Posts
Best Method for Site-Wide Variables
Feb 23, 2012 03:10 PM|LINK
I've seen a couple of ideas on this. Classes that house variables. Static classes with static variables using a Singleton-like structure. What are the methods and pros/cons? I'm looking to use some site-wide variables soon, but haven't given it a go yet.
global singleton
adamturner34
Contributor
4394 Points
1102 Posts
Re: Best Method for Site-Wide Variables
Feb 23, 2012 03:16 PM|LINK
What scope do you mean by site wide? Session scope? Application Scope?
Do the variables only need to be available in RAM or do you need to store them?
steventnorri...
Member
11 Points
14 Posts
Re: Best Method for Site-Wide Variables
Feb 23, 2012 03:25 PM|LINK
Application scope. These will be stored dictionaries, lists, and other tools used to identify mappings between SQL data and the visible representation as well as site-wide static data. I'm thinking of going with a singleton structure. It feels very smooth and right, but I want to know the different ideas, pros, and cons out there first.
SGWellens
All-Star
126033 Points
10311 Posts
Moderator
Re: Best Method for Site-Wide Variables
Feb 23, 2012 03:28 PM|LINK
Perhaps caching would fulfill your requirements:
http://msdn.microsoft.com/en-us/library/ms972379.aspx
My blog
adamturner34
Contributor
4394 Points
1102 Posts
Re: Best Method for Site-Wide Variables
Feb 23, 2012 03:43 PM|LINK
If you're going to be analyzing this data, I would suggest writing it either to XML or store it in the database.
steventnorri...
Member
11 Points
14 Posts
Re: Best Method for Site-Wide Variables
Feb 23, 2012 03:53 PM|LINK
SGWellens: That's an interesting feature I didn't know about. That would work great for some of the more static database pulls I'll be doing. I think the dictionaries and such would benefit from a application level instantiation. They may not be used often, but when they are used, I'd like them already created and sitting ready. (Although, giving it some thought cacheing with a large enough time dependency would render pretty much the same outcome for most all users).
AdamTurner34: This isn't so much data analysis as it is data pairing. For example, my SQL row headers were not created by me and do not have a user friendly form. I want a dictionary to map the SQL headers with the display text so I can fluidly grab that. I don't want to recreate the dictionary for this on each page, so application scoped. The cacheing would work well for the xml/database data on a whole though.
atconway
All-Star
16846 Points
2756 Posts
Re: Best Method for Site-Wide Variables
Feb 24, 2012 02:07 AM|LINK
Hopefully I am wrong here but other than the static lists, etc (which the suggestion for Application Caching is a great one and he one I recommend as well), you are not inferring that you want some type of global dictionary mapping of SQL values to global variables are you? I hope I am wrong here because I used to see that in VB6 where these huge monolithic modules were used to create global varibales that represented their SQL data equivilent and they were nasty. For example a SQL value of "CustomerLastName" might be "gFld_CustomerLastName". Global scope and so easy to step on the toes of varibales because no encapsulation of behavior or data was used via individual classes.
If for some reason what I described above is indeed what you want then I strongly recommend a different approach. This is the responsibility of the data model being mapped to the object model. Typically this happens low in the lowest layers of the application, and in return values are exposed via Properties on classes. Or use something like EF and this is doen for you already. Weather a busniess object, DTO, or something else, the values are never just represented by some gloal variable with no relationship to anything else all on its own.