J
Joseph Geretz
I've built a singleton class which I want to share among different
application clients (code below). I've confirmed that the singleton class
works properly within a single client. Although the application can acquire
multiple references to the class, all references point to a single class
instance. However, when loaded by different applications, each application
gets its own class instance. How can I extend the nature of this singleton
so that it provides one instance and only one instance regardless of the
number of clients / application domains which request it?
Thanks immensely for your advice!
- Joseph Geretz -
Singleton class coded according to the recommendation of:
http://www.yoda.arachsys.com/csharp/singleton.html
public sealed class Singleton
{
// The Singleton instance - the only instance ever created.
private static readonly Singleton m_Instance = new Singleton();
private static readonly string m_InstanceID =
Guid.NewGuid().ToString();
// Explicit static constructor to tell C# compiler not
// to mark type as beforefieldinit. Do not remove!
static Singleton()
{
// m_Instance could be created inside this static
// constructor, or simultaneous to its static
// definition as defined above. no difference.
}
// Private instance constructor prevents clients
// from creating their own instance. Only way to
// obtain an instance is to request the static
// Instance which hands out the single instance
// to all clients.
private Singleton()
{
}
public static Singleton Instance
{
get
{
return m_Instance;
}
}
public string InstanceID
{
get
{
return m_InstanceID;
}
}
application clients (code below). I've confirmed that the singleton class
works properly within a single client. Although the application can acquire
multiple references to the class, all references point to a single class
instance. However, when loaded by different applications, each application
gets its own class instance. How can I extend the nature of this singleton
so that it provides one instance and only one instance regardless of the
number of clients / application domains which request it?
Thanks immensely for your advice!
- Joseph Geretz -
Singleton class coded according to the recommendation of:
http://www.yoda.arachsys.com/csharp/singleton.html
public sealed class Singleton
{
// The Singleton instance - the only instance ever created.
private static readonly Singleton m_Instance = new Singleton();
private static readonly string m_InstanceID =
Guid.NewGuid().ToString();
// Explicit static constructor to tell C# compiler not
// to mark type as beforefieldinit. Do not remove!
static Singleton()
{
// m_Instance could be created inside this static
// constructor, or simultaneous to its static
// definition as defined above. no difference.
}
// Private instance constructor prevents clients
// from creating their own instance. Only way to
// obtain an instance is to request the static
// Instance which hands out the single instance
// to all clients.
private Singleton()
{
}
public static Singleton Instance
{
get
{
return m_Instance;
}
}
public string InstanceID
{
get
{
return m_InstanceID;
}
}