Circular reference problem Singleton

Posted by Ismail on Stack Overflow See other posts from Stack Overflow or by Ismail
Published on 2010-12-30T10:26:19Z Indexed on 2010/12/30 10:53 UTC
Read the original article Hit count: 214

I'm trying to creating a Singleton class like below where MyRepository lies in separate DAL project. It's causing me a circular reference problem because GetMySingleTon() method returns MySingleTon class and needs its access. Same way I need MyRepository access in constructor of MySingleTon class.

  public class MySingleTon
  {
    static MySingleTon()
    {
      if (Instance == null)
      {
        MyRepository rep = new MyRepository();
        Instance = rep.GetMySingleTon();
      }
    }
    public static MySingleTon Instance { get; private set; }
    public string prop1 { get; set; }
    public string prop2 { get; set; }
  }

© Stack Overflow or respective owner

Related posts about c#-4.0

Related posts about singleton