Home
  Latest posts
  My Writings
  My Code
  My Gallery
  About me
 
  rssfeed Syndication
 
Bloggtoppen.se
 
 
Links
  Cornerstone
  SweNug
 
Post categories
  misc (48)
  Architecture (21)
  C# (19)
  Asp.Net (2)
  Vb.Net (2)
  Training (7)
  Data (19)
  Events (40)
  Platform (2)
  Orcas (4)
  Updates (3)
  Methods (10)
  Tools (6)
  Announcements (14)
  Languages (1)
  Patterns (6)
  Opinions (11)
  Fun (3)
  Ineta (1)
  Opinion (0)
  Practices (2)
  WCF (5)
 
 
 
Asp.Net (2)
BUG: ASP.NET Data Source parameters Thursday, January 11, 2007

Today I wrote a little parameter to get todays date (interested in how, take a look at Fredriks post over here: http://fredrik.nsquared2.com/viewpost.aspx?PostID=355).

This is just a heads up, there's a some headache when trying to get theese to work. Appearently Visual Studio finds it ok to have the parameter class in the asp.net application project but the asp.net runtime doesn't. To get my parameter to work, I had to put it into a separate dll and reference that.

Leave a comment Comments (0)
 
I am the Key Master Thursday, January 20, 2005

No this is not a tribute to my favorite 80's movie Ghost busters....

Managing state keys
A popular tip I often give when delivering asp.net classes is to not let "free text" session strings hang around your system. Keys managed in this way will certanly cause trouble in the development lifecycle.

It's quite hard to keep track of them in a single human memory and even more difficult to actually synchronize the information across multiple human memory banks (maybe SOA could help solve the human to human memory synchronization issues ;)

This often leads to frustration and endless searches for the correct key data. Also misspelling at late friday nights are very common and leads to even more frustration.

The tip I usually give is to use constants instead. Constants stored in a central location, namely a Singleton class.

Quick example;

    public sealed class KeyMaster
    {
        private KeyMaster(){}
  
        public sealed class Session
        {
            private Session() {}
          
            ///


            /// A nifty ey to access the nifty session object.
            ///

            public const string MyNiftyKey = "MyNiftySessionKey";
      
        }
  
        public sealed class ViewState
        {
            private ViewState() {}

            ///
            /// A nifty ey to access the nifty session object.
            ///

            public const string MyNiftyKey = "MyNiftyViewStateKey";
        }

        public sealed class Cache
        {
            private Cache() {}

            ///
            /// A nifty ey to access the nifty session object.
            ///

            public const string MyNiftyKey = "MyNiftyCacheKey";
        }
    }

This will allows to easally access the keys in the form of:

    aNiftyObject = (ANiftyType)Session[KeyMaster.Session.MyNiftyKey];

Which gives us three main advantages:

   1. No more misspelling, I will get full intellisens for my keys with additional descriptions. This will clearly state what the key is used for.
   2. It will be much harder to missuse a key by accident and much easier to find the appropiate key,
   3. My development team will sleep better at friday nights.

While we're at it, let's talk about something very similar that also will help in handling the state bags.

Encapsulation of state reading / writing.

If I take it as practice to always encapsulate the retrievment of state objects into a static property, I will have a nicely refactored facility to reuse through out my entire application.

code:

    public class FlashCard
    {
        public static FlashCard SessionFlashCard
        {
            get
            {
                return (FlashCard)HttpContext.Current.Session[KeyMaster.Session.FlashCard];
            }
            set
            {
                HttpContext.Current.Session[KeyMaster.Session.FlashCard] = value;
            }
        }
    }

Maybe these tips will give help reduce frustration in your development life time cycle. Safe googling....

Leave a comment Comments (4)