Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Global Objects
Message
De
03/09/2007 12:45:03
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
À
02/09/2007 14:24:57
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Titre:
Versions des environnements
Environment:
C# 2.0
OS:
Windows XP SP2
Network:
Windows 2000 Server
Database:
MS SQL Server
Divers
Thread ID:
01251812
Message ID:
01252011
Vues:
21
This message has been marked as a message which has helped to the initial question of the thread.
John,

Another part of your question mentioned Not wanting to instanitate the class every time you needed to access the settings data. There is a design pattern called the Singleton Design Pattern that addresses this issue also. Essentially the class itself can check to see if has already been instantiated before calling the constructor. I use a variation of what Rick mentioned where I have a settings class that uses the singelton design pattern. I instantiate the settings class from my main application object but can get a reference to it from anyother class as needed without creating another instance. Within this settings class all the settings properties are static and read from xml file or database or ?.
Tim

>>Statics are basically global instances with values that persist for the lifetime of an application.
>>
>>A good approach that I use in every app is that I have an App class in every project that has a number of static instance variables hanging off of it. So anything 'application-wide' usually hangs off this object.
>>
>>So I can go to say App.Configuration.ApplicationName or App.Configuration.ConnectionString from anywhere in the app. I have App.Constants any static hashtables and collection data that is frequently reused and doesn't need to be reloaded from the database etc. all that stuff lives off this App object as static data. Basically a static constructor (or field assignment which is bascially the same thing) makes sure the data gets loaded only on first access of the static class - after that all the data is read only or write rarely - otherwise you need to be careful about multi-threading issues.
>>
>>If Configuration is what you're after you should maybe check out an article I wrote a few years back for a generic configuration class for .NET that handles this all for you - you create a class and simply add properties and it reads and writes the configuration settings in various stores including config files.
>>
>>http://www.west-wind.com/presentations/configurationclass/configurationclass.asp
>>
>>Couldn't live without that class in any of my applications today...
>>
>>+++ Rick ---
>>
>>
>>>Something I'm not quite understanding about C# and .NET
>>>
>>>Lets say... your app has a class that goes out and let's say reads all the config info for your application, and stores it internally.
>>>
>>>I wouldn't think that you would want to create a new instance of that class and reread the data each time, I would just want to be able to access the data from memory when needed.
>>>
>>>Sort of the equivalent of the application object in VFP.
>>>
>>>So... how would you normally go about that? (Or don't you?)
>>>
>>>Is there a way to get a pointer to the object that contains main?
>
>Cool that is exactly what I am working on!
>
>Thanks!!!!!!!!!!!!
Timothy Bryan
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform