I have a C# MVC3 site. However, I needed to share objects to multiple classes in same request.
The other requests cannot access / do not know the shared objects exist.
After the request end, the shared objects should be deleted.
This example code can the object to each request instead of sharing object in one request only.
Class ShareObjects
{
private static SomeThing _Data = null;
public static SomeThing Data
{
get
{
if (_Data == null)
{
_Data = new SomeThing();
}
return _Data;
}
}
}
Class ObjectA
{
public ObjectA()
{
var data = ShareObjects.Data;
//Do stuff
}
}
Class ObjectB
{
public ObjectB()
{
var data = ShareObjects.Data;
//Do stuff
}
}