Question

I was wondering if anyone could help me understand if what I am doing is a lot of overhead or not. It is currently working but I am not sure if this could slow down the site or not. I have a workflowobj class in which i set all the session variables. This class in instantiated on the pages that need it:

WorkFlowObj wfo = new WorkFlowObj(this.Session, this.Response); wfo.VendorRedirect();

I need this because I need to be able to keep track of session variables and at the same time be able to keep track of a more complicated page workflow in one place. This solution already already works for me, but the only problem is that I am not sure if passing around the session and the response objects creates a lot of OVERHEAD. Can anyone tell me if this is terribly inefficient?? Below is the code for the workflowobj class.

    public class WorkFlowObj
    {
        private System.Web.SessionState.HttpSessionState _pagesession;
        private HttpResponse _HttpResponse;

        private int _userid;
        private string _vendorname;
         ///private other vars here
     }
    public int UserID
    {
        get
        {
            return _userid;
        }
    }


    public WorkFlowObj(System.Web.SessionState.HttpSessionState pagesession, HttpResponse _response)
    {
        _pagesession = pagesession;
        _HttpResponse = _response;
         Initialize();

    }

    private void Initialize()
    { 
    //initialize variables from session
    _userid=_pagesession["userid"].ToString();
    }


    public void VendorRedirect()
    {
        switch (this._vendorname)
        {

            case "1":
                this._HttpResponse.Redirect(page1);
                break;
            case "2":
                this._HttpResponse.Redirect(page2);
                break;
                //etc
            default:
                //dostuff;
                break;
        }
    }
}
Was it helpful?

Solution

I would not create dependencies to System.Web in your workflow objects, just pass the variables that the workflow objects need to make decision and execute business logic. There is no overhead passing objects around, they are just pointers under the hood.

One issue I could see happening is accidental use of statics in another layer that get tied to your Page state, thus not allowing the GC to clean up ie: classic out of memory exception or app pool recycle.

OTHER TIPS

As Rick says, I wouldn't create dependencies to System.Web in your middle-tier objects if you can avoid it.

But if you can't avoid it, you can avoid passing around the Session object by using the static System.Web.HttpContext class. This lets you do something like:

userid = (String)System.Web.HttpContext.Current.Session["userid"];

As long as it's executing on the same thread (and therefore in the same context) as the request from the browser.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top