You can use HTTPModule (hit every time) which checks the Application Object with some key (unique for a session, probably you can use SessionId + something within the key). This we are doing to access previous session's object , in case we don't want this, then we can set with some key not unique to a particular session.
Now as the module is hit, and we find no object in Application Object for the particular session we will create the object and will set in this HTTPModule Class as static.
Then the following code might help in case we find no object in HTTPApplication object for the current session(in case we dont need previous session's object then we can use HTTPSession object also to check for ClassA object's availability, even a flag with in HTTPSession will suffice, no need to save any object in HTTPSession, module class will give that).
In HTTPModule class the following should be added:
Static variable which can be accessed from this HTTPModule class by any other class of your application.
/* HTTP Module Class */
public class SomeModuleClass
{
public static ClassA classA = null;
private void someFunctionOfModuleFiringEverytime()
{
/* if there is no instance of ClassA in HTTPApplication or HTTPSession object*/
SessionManager sessionManager = new SessionManager();
/* one object of SessionManager gives back one object of ClassA always*/
classA = sessionManager.getClassA();
}
}
/* an assembly which is making the Class A instance*/
public class SessionManager
{
private ClassA classInstance=null;
public ClassA getClassA()
{
if (classInstance == null)
classInstance = new ClassA();
return classInstance;
}
}
/* class from another assembly*/
public class ClassA
{
public ClassA()
{
}
}