Appliocation State Via Singleton

Last post 08-08-2007 3:11 PM by warnov. 2 replies.

Sort Posts:

  • Appliocation State Via Singleton

    08-07-2007, 6:37 PM
    • Member
      45 point Member
    • warnov
    • Member since 06-26-2003, 8:44 PM
    • Bogotá Colombia
    • Posts 18

    Hi,

    I have this web application. And created a Singleton class in the App_Code folder, so it is accesible through the entire application. The web app, requiere some data from a SQL Server, describirng all the countries, their states and its capitals. So this is information that barely have to change (maybe some nuts drop an atomic bomb over a country and it just dissapear, and then the DB will have to change). In a common approach, the geographic data will be cached or stored in an Application variable. But with te singleton I have mentioned before, I just had to include in it a DataSet with this info when the application starts. Then the geographic data remain accessible to all the app, in a fast way, and without having to visit the dataserver again. Everything worked fine.

    Nevertheless, I think this is too wonderful to be real! And I have never seen an article talking about this approaching for application state managment. What do you think about this? Have you ever seen or made anything like this? Do you think this approach have spetial side effects? Will the described data be too much load for the server memory when it will be in production serving like a thousand of clients?

     I'll be glad hearing your opinion.

    PD.: I didn't use Cache, because the data will never expire. And I didn't use application variables, because, I don't like making castings (boxing and unboxing) everytime I need to query the data: This is: if I want to read the dataset I have to perform something like this:  ((DataSet)Application["myData"].Tables.Count) but with the singleton: ContentManager.myData.Tables.Count. As you can see the acces is more natural, and I think there will be a gain in performance, since no casting is made.

     

    Open mind 4 a different coding
  • Re: Appliocation State Via Singleton

    08-07-2007, 9:05 PM
    • All-Star
      21,646 point All-Star
    • gunteman
    • Member since 07-11-2007, 12:57 PM
    • Norrköping, Sweden
    • Posts 3,176
    -- "Mark As Answer" if my reply helped you --
  • Re: Appliocation State Via Singleton

    08-08-2007, 3:11 PM
    • Member
      45 point Member
    • warnov
    • Member since 06-26-2003, 8:44 PM
    • Bogotá Colombia
    • Posts 18

    I have read your post and it has a good point about the overuse of the singleton. But I have exposed valid reasons for implementing the singleton pattern: Global Access, and just one instance is required in the system. In addition it offers more performance than cache (at first sight, I would like to know if I'm wrong). In conclusion, It don't give me a straight path for being convinced in using the singleton, the cache, or in this case your static class. 

    Open mind 4 a different coding
Page 1 of 1 (3 items)