Check my blog:
http://spaces.msn.com/sholliday/ 10/24/2005 entry
You can easily convert this to a Application holder.
...
If you're not using a server farm, then my blog idea (converted to
application) could work.
If you're using a server farm, you may need to go to remoting, and have all
members of the web server farm talk to the 1 remoting server.
Actually, I just found the code for the Application one.
Read the blog for the explanation, and here is the code.
using System;
using System.Collecti ons;
using System.Collecti ons.Specialized ;
namespace GranadaCoder.Ca chingFramework
{
public class WebApplicationD ataStore : IDataStore
{
private static string WEB_APPLICATION _OBJECT_GUID =
"B777D4C2-1576-40C3-88F8-FA16E94DDC90"; //ensure uniqueness, other than
that doesn't serve any purpose
private static WebApplicationD ataStore singletonInstan ce = null;
private Hashtable m_memoryStore = null;
private WebApplicationD ataStore()
{
this.m_memorySt ore = new Hashtable();
}
public static WebApplicationD ataStore GetInstance()
{
if (null != System.Web.Http Context.Current )
{
if (null != System.Web.Http Context.Current .Application )
{
if (null !=
System.Web.Http Context.Current .Application[WEB_APPLICATION _OBJECT_GUID] )
{
singletonInstan ce =
((WebApplicatio nDataStore)(Sys tem.Web.HttpCon text.Current.Ap plication.Get(W E
B_APPLICATION_O BJECT_GUID)));
}
}
}
if ((singletonInst ance == null))
{
singletonInstan ce = new WebApplicationD ataStore();
System.Web.Http Context.Current .Application.Ad d(WEB_APPLICATI ON_OBJECT_GUID,
singletonInstan ce);
}
return singletonInstan ce;
}
public void Clear()
{
this.m_memorySt ore.Clear();
}
public void Add(string key, object value)
{
if (this.m_memoryS tore.Contains(k ey))
{
this.m_memorySt ore.Remove(key) ;
}
this.m_memorySt ore.Add(key, value);
}
public object Remove(string key)
{
object returnObject = null;
if (null != this.m_memorySt ore )
{
if (this.m_memoryS tore.Contains(k ey))
{
returnObject = this.m_memorySt ore[key];
this.m_memorySt ore.Remove(key) ;
}
}
return returnObject;
}
public object this[string key]
{
get
{
if (null != this.m_memorySt ore[key] )
{
return this.m_memorySt ore[key];
}
return null;
}
}
public int Size
{
get
{
if (null != this.m_memorySt ore )
{
return this.m_memorySt ore.Count;
}
return 0;
}
}
}
}
<ne************ @hotmail.com> wrote in message
news:11******** **************@ y43g2000cwc.goo glegroups.com.. .
I want to share one instance of an object across an ASP dot net
application, and I'm trying to weigh the pros and cons of the following
two approaches:
a) Storing the object in ApplicationStat e
b) Storing the object in a static member variable (utilizing a
singleton design pattern)
Any recommendations on which method would be more suitable?
What happens in each of these cases if IIS decides to spawn a new app
domain?
Are there any other approaches that might be better than the ones I
mentioned?
The object in question is a dot net class wrapping a COM component.
The class creates an SSL session to a proprietary device that manages
encryption and decryption.
Thanks,
Jonathan