How to retrieve an instance of HttpApplicationState

I have been using the Application property of the System.Web.UI.Page class frequently. However, I want to centralize some of the functions that use this object in my Business Logic Layer which doesn't inherit from the System.Web.UI.Page class. How can I use this object in my Business Logic Layer class?
LVL 20
Russ SuterAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
SammyConnect With a Mentor Commented:
try something like this
hope this helps

 public class myObject
    {
        public myObject()
        { }
        HttpApplicationState _appState = HttpContext.Current.Application;
      public  HttpApplicationState AppState
        {
            get { return _appState; }
            set { _appState = value; }
        }
    }
//Usage in any other page or Class
 myObject myObject = new myObject();
            myObject.AppState.Add("1", 1);

Open in new window

0
 
mjhoaglandCommented:
You can pass it as a parameter to your business logic layer.  That way you can know the reference is always up to date.
0
 
Russ SuterAuthor Commented:
Seems simple enough. I can just refer to HttpContext.Current.Application whenever I need the instance. Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.