Click here to Skip to main content
15,886,199 members
Articles / Web Development / HTML

Web Application State

Rate me:
Please Sign up or sign in to vote.
4.87/5 (16 votes)
15 Apr 2008CPOL7 min read 83K   1.2K   127  
This article explains how to maintain the web application state.
using System;
using System.Collections.Generic;
using AndrewGolik.Training.Components.Storage;

namespace AndrewGolik.Training.Components
{
    public abstract class
        StateObject<T1, T2>
        where T1 : StateObject<T1, T2>
        where T2 : IStorage<T1>, new()
    {
        private object _id;

        private readonly IStorage<T1> _storageImp;

        public object ID
        {
            get { return _id; }
            set { _id = value; }
        }

        protected StateObject()
        {
            _id = Guid.NewGuid();
            _storageImp = new T2();
        }

  
        public virtual void Save()
        {
            _storageImp.Save(_id, (T1) this);
        }

        public static T1 Get(object key)
        {
            T2 storageImp = new T2();
            return storageImp.Get(key);
        }

        public static List<T1> GetAll()
        {

            T2 storageImp = new T2();
            return storageImp.GetAll(typeof(T1));

        }

        public static void Delete(object ID)
        {
            T2 storageImp = new T2();
            storageImp.Delete(ID);
        }

        public static void Clear()
        {
            T2 storageImp = new T2();
            storageImp.Clear();

        }
    }
}

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
Belarus Belarus
Andrew Golik is a software professional working in Minsk, Belarus.
He enjoys design infrastructures based on object oriented paradigm. His programming experience includes ASP, ASP.NET, .NET, COM, JAVA, PHP, DHTML, AJAX, blah blah blah....

Andrew Golik's Blog

Comments and Discussions