Q: Initialising and updating a class with only static members & database dependency

Discussion in 'ASP .Net' started by mark4asp, Jul 5, 2007.

  1. mark4asp

    mark4asp Guest

    Q: Initialising and updating a class with only static members &
    database dependency

    I have a class with the following members:

    public static List<ACIS> ACIS_List;

    static AssetClass() { // blah }

    public static ACIS Get_ACIS(string sACISCode) { // blah }

    public static ACIS Get_ACIS(int iACIS_Id) { // blah }

    Furthermore there are another 6 classes like this - each one has a
    static List<T> with methods used to search the List<T> to return data.

    Classes fall into 2 different types: (a) those with more or less
    fixed, unchanging, data and (b) those having data which may change
    daily.

    Q1. What is the best way to initialise all these classes at once? I
    would like to load all these classes with data at once because that
    would only need one hit to the database.

    Q2. Taking the reply to Q1 above into account, what is the best kind
    of constructor to use? static, private, etc.? Should I be using the
    constructor to load the class List<T> with data?

    Q3. If some of these Lists become out-of-date, can I set up a
    dependency which works to update the List<T> with the most recent data
    - i.e. something which works like a cache dependency?
     
    mark4asp, Jul 5, 2007
    #1
    1. Advertising

  2. RE: Q: Initialising and updating a class with only static members & da

    Probably the best way to initialize your classes all at once is to call a
    method from your global.asax Application_Start handler that gets the data
    from the database, and (however your operation works) makes some sort of
    action on each static class that causes it to do whatever it does (for
    example, excercize a static ctor).

    Regarding having a dependency, you could certainly use a SQLCacheDependency
    to call your method that you put into the Application_Start handler to
    refresh your classes.

    Not entirely sure whether having static classes is the answer here, though.
    it might be better just to cache the stuff as instances and use the
    SqlCacheDependency to invalidate the cached data.
    -- Peter
    Site: http://www.eggheadcafe.com
    UnBlog: http://petesbloggerama.blogspot.com
    BlogMetaFinder(BETA): http://www.blogmetafinder.com



    "mark4asp" wrote:

    > Q: Initialising and updating a class with only static members &
    > database dependency
    >
    > I have a class with the following members:
    >
    > public static List<ACIS> ACIS_List;
    >
    > static AssetClass() { // blah }
    >
    > public static ACIS Get_ACIS(string sACISCode) { // blah }
    >
    > public static ACIS Get_ACIS(int iACIS_Id) { // blah }
    >
    > Furthermore there are another 6 classes like this - each one has a
    > static List<T> with methods used to search the List<T> to return data.
    >
    > Classes fall into 2 different types: (a) those with more or less
    > fixed, unchanging, data and (b) those having data which may change
    > daily.
    >
    > Q1. What is the best way to initialise all these classes at once? I
    > would like to load all these classes with data at once because that
    > would only need one hit to the database.
    >
    > Q2. Taking the reply to Q1 above into account, what is the best kind
    > of constructor to use? static, private, etc.? Should I be using the
    > constructor to load the class List<T> with data?
    >
    > Q3. If some of these Lists become out-of-date, can I set up a
    > dependency which works to update the List<T> with the most recent data
    > - i.e. something which works like a cache dependency?
    >
    >
     
    =?Utf-8?B?UGV0ZXIgQnJvbWJlcmcgW0MjIE1WUF0=?=, Jul 5, 2007
    #2
    1. Advertising

  3. mark4asp

    mark4asp Guest

    Re: Q: Initialising and updating a class with only static members & da

    On 5 Jul, 15:54, Peter Bromberg [C# MVP]
    <> wrote:
    > Probably the best way to initialize your classes all at once is to call a
    > method from your global.asax Application_Start handler that gets the data
    > from the database, and (however your operation works) makes some sort of
    > action on each static class that causes it to do whatever it does (for
    > example, excercize a static ctor).
    >
    > Regarding having a dependency, you could certainly use a SQLCacheDependency
    > to call your method that you put into the Application_Start handler to
    > refresh your classes.
    >
    > Not entirely sure whether having static classes is the answer here, though.
    > it might be better just to cache the stuff as instances and use the
    > SqlCacheDependency to invalidate the cached data.
    > -- Peter
    > Site: http://www.eggheadcafe.com
    > UnBlog: http://petesbloggerama.blogspot.com
    > BlogMetaFinder(BETA): http://www.blogmetafinder.com
    >
    >
    >
    > "mark4asp" wrote:
    > > Q: Initialising and updating a class with only static members &
    > > database dependency

    >
    > > I have a class with the following members:

    >
    > > public static List<ACIS> ACIS_List;

    >
    > > static AssetClass() { // blah }

    >
    > > public static ACIS Get_ACIS(string sACISCode) { // blah }

    >
    > > public static ACIS Get_ACIS(int iACIS_Id) { // blah }

    >
    > > Furthermore there are another 6 classes like this - each one has a
    > > static List<T> with methods used to search the List<T> to return data.

    >
    > > Classes fall into 2 different types: (a) those with more or less
    > > fixed, unchanging, data and (b) those having data which may change
    > > daily.

    >
    > > Q1. What is the best way to initialise all these classes at once? I
    > > would like to load all these classes with data at once because that
    > > would only need one hit to the database.

    >
    > > Q2. Taking the reply to Q1 above into account, what is the best kind
    > > of constructor to use? static, private, etc.? Should I be using the
    > > constructor to load the class List<T> with data?

    >
    > > Q3. If some of these Lists become out-of-date, can I set up a
    > > dependency which works to update the List<T> with the most recent data
    > > - i.e. something which works like a cache dependency?- Hide quoted text -

    >
    > - Show quoted text -


    Thanks for the reply Peter. It may be easier to use the Cache but, it
    seems to me, not the most efficient way to get things done. When I
    want to access say a List<Manager> I must get the object from the
    cache, cast it to List<Manager>, check to see whether it's null (then
    possibly reload it from the database) before it's ready for use. This
    is my dilema. Ease of using the cache against a slight overhead. I
    shall try both solutions, but probably go with the one we know works
    right now.

    PS: I would be very nice if microsoft were to expand the database
    dependencies so that objects not in the cache (such as my List<T>s)
    could also be set to null when a database table is changed. (Microsoft
    - Is anyone listening to me?)
     
    mark4asp, Jul 5, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. SaravanaKumar
    Replies:
    6
    Views:
    9,525
    Tony Morris
    Oct 19, 2004
  2. JFCM
    Replies:
    4
    Views:
    5,788
  3. Tim Clacy
    Replies:
    3
    Views:
    604
    Nick Hounsome
    Mar 4, 2004
  4. Fred
    Replies:
    6
    Views:
    419
  5. Jens Henrik Goebbert

    initialising static member with static methode

    Jens Henrik Goebbert, Oct 24, 2007, in forum: C++
    Replies:
    3
    Views:
    1,002
Loading...

Share This Page