Convert an ASP.net Singleton Session Instance to an object?

EDIT: You don't need to change the instance calls if you do the code above. In most instance calls, they create the static object if null and stuff it away in the static member variable and continue to hand the same one out (with some double lock checks perhaps). In the code above, you don't do that - you turn around and give out the one in their session state dictionary so each each will get a different one The term instance in that case will be a little mis-leading but you don't have to change all the calling code.It will logically be an instance of their shopping cart Using the HttpContext.Current.

Session dictionary will allow you to store a cart in memory per shopping user The downside of an in-memory session is if the IIS application pool recycles, it will be gone. Also, if you ever have to add another web server (scale out), you'll need to use NLB affinity - it just limits your options. Your memory also grows since their cart would stay in memory for the lifetime of the session - but that's a good problem for a shopping site :) But, it's dead simple and light weight Other options would be to either store session state in a DB via configuration or roll your own shopping cart tables Yet another option would be to use cloud storage - something like Azure table services.

That way you get the best of both worlds - you don't have to maintain your SQL server, you get redundancy and durability across recycles etc... And hey - you can play with a new technology at the same time :).

EDIT: You don't need to change the instance calls if you do the code above. In most instance calls, they create the static object if null and stuff it away in the static member variable and continue to hand the same one out (with some double lock checks perhaps). In the code above, you don't do that - you turn around and give out the one in their session state dictionary so each each will get a different one.

The term instance in that case will be a little mis-leading but you don't have to change all the calling code. It will logically be an instance of their shopping cart. ... Using the HttpContext.Current.

Session dictionary will allow you to store a cart in memory per shopping user. The downside of an in-memory session is if the IIS application pool recycles, it will be gone. Also, if you ever have to add another web server (scale out), you'll need to use NLB affinity - it just limits your options.

Your memory also grows since their cart would stay in memory for the lifetime of the session - but that's a good problem for a shopping site :) But, it's dead simple and light weight. Other options would be to either store session state in a DB via configuration or roll your own shopping cart tables. Yet another option would be to use cloud storage - something like Azure table services.

That way you get the best of both worlds - you don't have to maintain your SQL server, you get redundancy and durability across recycles etc... And hey - you can play with a new technology at the same time :).

Added point about . Instance not having to change. – bryanmac Oct 14 at 0:56 perfect @bryanmac - see I do accept answers - when they're as good as yours :) – Ed Bloom Oct 14 at 15:04 :) Thx -I usually answer anyways but I poke hoping to help folks.

Some don't realize .. – bryanmac Oct 14 at 15:06.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions