Click here to Skip to main content
15,895,557 members
Articles / Web Development / ASP.NET

Advancing the Model-View-Presenter Pattern - Fixing the Common Problems

Rate me:
Please Sign up or sign in to vote.
4.53/5 (28 votes)
6 Sep 2007CPOL7 min read 187.5K   611   105  
Addressing the common issues related to the MVP pattern using ASP.NET and WinForms clients.
using System;
using System.Collections;
using System.Web;
using System.Web.SessionState;

using Sample.Presentation;

/// <summary>
/// WebSessionProvider wraps asp.net's session object for use with the MVP
/// pattern.  The presentation library shouldn't know about anything "downstram," 
/// which means no references to System.Web etc.  Because the class implements
/// ISessionProvider (in the Presentation project), state can still be maintained 
/// using the HttpSessionState object. 
/// </summary>
public class WebSessionProvider : ISessionProvider
{
    private HttpSessionState Session
    {
        get { return HttpContext.Current.Session; }
    }

    public void Add( string name, object value )
    {
        Session.Add(name, value);
    }

    public void Clear()
    {
        Session.Clear();
    }

    public bool Contains( string name )
    {
        return Session[name] != null;
    }

    #region ISessionProvider Members

    object ISessionProvider.this[string name]
    {
        get
        {
            return Session[name];
        }
        set
        {
            Session[name] = value;
        }
    }

    object ISessionProvider.this[int index]
    {
        get
        {
            return Session[index];
        }
        set
        {
            Session[index] = value;
        }
    }

    #endregion
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer PageLabs
United States United States
I'm the founder of PageLabs, a web-based performance and SEO optimization site.

Give your site a boost in performance, even take a free speed test!

http://www.pagelabs.com

Comments and Discussions