All GetSessionObject() would do is return the session variable and convert it into the ClassName object.
I have never heard of the class factory design pattern, and was an interesting read. However, it follows the pattern I was hoping to avoid, which would basically be creating the instance of a class and calling another method to return the session object. An example of what I have is below:
ClassName obj = new ClassName().GetSessionObject();
public class ClassName
{
public ClassName()
{
}
public GetSessionObject()
{
return (ClassName)HttpContext.Current.Session["ClassName"];
}
}
Now what I am trying to do is minimize the request and call only
ClassName obj = new ClassName(); instead of calling the additional GetSessionObject(); explicitly. Now it would be easy if ClassName was a container / wrapper, and there was another class beneath it that contained all the information, but this is not the case.
Is it possible to do this? The best, but unavailable, method would be to re-assign the "this" reference, however, this is not allowed through csharp.