does class reference itself static anti pattern in prism

Posted by Michael Riva on Programmers See other posts from Programmers or by Michael Riva
Published on 2014-06-06T07:38:03Z Indexed on 2014/06/06 9:38 UTC
Read the original article Hit count: 213

I have an application and my desing approach look like this:

class Manager
{
    public int State;

    static Manager _instance = null;
    public static Manager Instance
    {
        get { return _instance; }
        set
        {
            if (_instance == value)
                return;
            _instance = value;
        }
    }

    public Manager()
    {
        State = 0;
        Instance=this;
    }
}
class Module1
{
    public void GetState()
    {
        Console.WriteLine(Manager.Instance.State);
    }
}
class Module2
{
    public void GetState()
    {
        Console.WriteLine(Manager.Instance.State);
    }
}
class Module3
{
    public void GetState()
    {
        Console.WriteLine(Manager.Instance.State);
    }
}

Manager class already registered in Bootstrapper like :

 protected override void ConfigureContainer()
 {
       base.ConfigureContainer();
       Container.RegisterType<Manager>(new ContainerControlledLifetimeManager());
 }
 protected override void InitializeModules()
 {
      Manager man= Container.Resolve<Manager>();
 }

Question is do I need to define my manager object as static in its field to be able to reach its state? Or this is anti pattern or bad for performance?

© Programmers or respective owner

Related posts about c#

Related posts about design-patterns