I have a project consisting of three projects,
- WCF service
- Asp.net MVC 3 application
- Class library.
The one in the class library is my singleton, which I have made like this;
public sealed class Singleton
{
public static Singleton Instance { get; set; }
private Singleton()
{
}
public static Singleton Instance
{
get
{
if (Instance == null)
Instance = new Singleton();
return Instance;
}
}
}
The thing is, I put a Debug.WriteLinein the constructor, and it gets called twice.
What I am trying to do is use the singleton from the mvc 3 application and from the WCF service, but they make different instances. Why?
EDIT: I tried a treadsafe singleton earlier. It made no difference.
AppDomains. EachAppDomainhas its own static variables, and thus its own singleton. And that's necessary, because (most) objects can't be shared betweenAppDomains.MyClass.Instancesingletons in favour of IoC singletons. | @Hadas what do you mean? Your statement makes no sense at all.