does class reference itself static anti pattern in prism
- by Michael Riva
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?