I
INeedADip
I want to get some feedback so don't hold back.
I have a webservice that is responsible for Formatting a ton of information
that is then queried by other applications (agents) that utilize it (the
info).
All this "formatting" and logic I am talking about needs to be done in a
centralized place and accessed by the agents. That is why we chose to go
with a web service.
Now...all this formatting needs to be done and held in memory so the agents
don't have to wait for it.
So we decided to implement a sort of singleton pattern...what do you guys
think?
Here is some sample code:
public class TheManager
{
private static object lockObject = new Object();
private const string CACHE_MANAGER = "Cache:Manager";
private List<InfoPacket> _preparedPackets;
private TheManager() { initFunction(); }
public static InfoPacket GetInfoPacket() {
getManager().getInfoPacket(); }
public InfoPacket getInfoPacket() { ......some code ..... return
this._preparedPackets[0] }
private static TheManager getManager()
{
object o =
System.Web.HttpContext.Current.Application.Get(CACHE_MANAGER);
TheManager = oManager;
if(o == null)
{
lock(lockObject)
{
o =
System.Web.HttpContext.Current.Application.Get(CACHE_MANAGER);
if (o == null)
{oManager = new TheManager();
System.Web.HttpContext.Current.Application.Add(CACHE_MANAGER,oManager);}
else oManager = (TheManager)o;
}
}
else oManager = (TheManager)o;
return oManager;
}
}
So now in our web service (*.asmx) we can call TheManager.GetInfoPacket()
and a prepared packet is returned. Again, this is just a snippet of the
code..so we have functions and threads that are preparing the packet. We
are very consious of threading (utilizing lock() where needed). It has
performed VERY well and everything seems to be going as planned.
What do you guys think of a Singleton-esk pattern like the one above?
I have a webservice that is responsible for Formatting a ton of information
that is then queried by other applications (agents) that utilize it (the
info).
All this "formatting" and logic I am talking about needs to be done in a
centralized place and accessed by the agents. That is why we chose to go
with a web service.
Now...all this formatting needs to be done and held in memory so the agents
don't have to wait for it.
So we decided to implement a sort of singleton pattern...what do you guys
think?
Here is some sample code:
public class TheManager
{
private static object lockObject = new Object();
private const string CACHE_MANAGER = "Cache:Manager";
private List<InfoPacket> _preparedPackets;
private TheManager() { initFunction(); }
public static InfoPacket GetInfoPacket() {
getManager().getInfoPacket(); }
public InfoPacket getInfoPacket() { ......some code ..... return
this._preparedPackets[0] }
private static TheManager getManager()
{
object o =
System.Web.HttpContext.Current.Application.Get(CACHE_MANAGER);
TheManager = oManager;
if(o == null)
{
lock(lockObject)
{
o =
System.Web.HttpContext.Current.Application.Get(CACHE_MANAGER);
if (o == null)
{oManager = new TheManager();
System.Web.HttpContext.Current.Application.Add(CACHE_MANAGER,oManager);}
else oManager = (TheManager)o;
}
}
else oManager = (TheManager)o;
return oManager;
}
}
So now in our web service (*.asmx) we can call TheManager.GetInfoPacket()
and a prepared packet is returned. Again, this is just a snippet of the
code..so we have functions and threads that are preparing the packet. We
are very consious of threading (utilizing lock() where needed). It has
performed VERY well and everything seems to be going as planned.
What do you guys think of a Singleton-esk pattern like the one above?