Is this safe?

Discussion in 'ASP .Net' started by JezB, Dec 8, 2003.

  1. JezB

    JezB Guest

    I have a static class that is instantiated once on Application_Start in
    global.asax :-

    protected void Application_Start(Object sender, EventArgs e)
    {
    int dialectID = 1;
    Dialect.SetDialect(dialectID);
    }

    The static Dialect class is defined:

    public class Dialect
    {
    public static int DialectID;
    public static Placeholders Placeholders; // reference to Placeholders
    class

    public static void SetDialect(int dialectID)
    {
    DialectID = dialectID;
    Placeholders = new Placeholders(DialectID);
    }
    //etc
    }

    The Placeholder class constructor fetches some data from a database and
    stores it in a HybridDictionary. I want this data to only be fetched once
    per user sesison and always available to all webform pages through the
    Dialect class. I have tried this code and it all works but I have started to
    wonder how? I have taken no steps to store either the Placeholders class nor
    the Dialect class in Session or Application state, but it always seems to be
    available. Is this by virtue of the Dialect class being static ?

    Is this a safe and efficient way to do this ?
     
    JezB, Dec 8, 2003
    #1
    1. Advertising

  2. JezB

    JezB Guest

    Incidentally, the data IS only fetched once, I get at the data via other
    exposed methods in the Placeholders class, eg
    Dialect.Placeholders.Expand(lookUpKey);

    > I have a static class that is instantiated once on Application_Start in
    > global.asax :-
    >
    > protected void Application_Start(Object sender, EventArgs e)
    > {
    > int dialectID = 1;
    > Dialect.SetDialect(dialectID);
    > }
    >
    > The static Dialect class is defined:
    >
    > public class Dialect
    > {
    > public static int DialectID;
    > public static Placeholders Placeholders; // reference to Placeholders
    > class
    >
    > public static void SetDialect(int dialectID)
    > {
    > DialectID = dialectID;
    > Placeholders = new Placeholders(DialectID);
    > }
    > //etc
    > }
    >
    > The Placeholder class constructor fetches some data from a database and
    > stores it in a HybridDictionary. I want this data to only be fetched once
    > per user sesison and always available to all webform pages through the
    > Dialect class. I have tried this code and it all works but I have started

    to
    > wonder how? I have taken no steps to store either the Placeholders class

    nor
    > the Dialect class in Session or Application state, but it always seems to

    be
    > available. Is this by virtue of the Dialect class being static ?
    >
    > Is this a safe and efficient way to do this ?
    >
    >
     
    JezB, Dec 8, 2003
    #2
    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. Gabriel Rossetti
    Replies:
    0
    Views:
    1,394
    Gabriel Rossetti
    Aug 29, 2008
  2. Replies:
    1
    Views:
    375
    Brian Candler
    Aug 12, 2003
  3. Aredridel

    Not just $SAFE, but damn $SAFE

    Aredridel, Sep 2, 2004, in forum: Ruby
    Replies:
    19
    Views:
    264
  4. Farrel Lifson

    $SAFE =4 safe enough?

    Farrel Lifson, Aug 29, 2006, in forum: Ruby
    Replies:
    7
    Views:
    120
    Eric Hodel
    Aug 31, 2006
  5. John Nagle
    Replies:
    5
    Views:
    509
    John Nagle
    Mar 12, 2012
Loading...

Share This Page