Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7583979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:48:45+00:00 2026-05-30T18:48:45+00:00

How can I share ‘global’ application level context data between all objects living in

  • 0

How can I share ‘global’ application level context data between all objects living in an application. I’m thinking in terms of the currently logged on user record, which branch the user has opened to work on for a session, etc. How can I make this information available to all my forms and the classes they use for business logic services?

Just having one big global singleton AppContext object doesn’t appeal to me, but I can’t think of anything else right now. Maybe extend the Application class to offer a context service to all forms? I haven’t worked on desktop apps for some time and have come to rely on e.g. the ever present Session object in ASP.NET.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T18:48:47+00:00Added an answer on May 30, 2026 at 6:48 pm

    I think the concept of a browser “session” was invented to maintain state across browser requests. That really isn’t an issue for desktop apps. You could define a typed class with info about the user: id, email, name, etc. Basically whatever you would store in session. When someone logs in, create a new instance and assign it to a static variable. When they log out, set the static variable to null.

    If you wanted it to behave more like HttpSessionState does (arbitrary key/value pairs), replace your typed class with a Hashtable.

    EDIT

    Depending on what you are planning to keep in session, my answer might vary, but here is a singleton-like class I quickly came up with.

    public class AppContext
    {
        private static AppContext current;
    
        // reference to the current app context
        public static AppContext Current
        {
            get { return current; }
        }
    
        // prevents new instance from being created externally
        private AppContext() { }
    
        // call when a user logs in
        public static void Login(AppUser user)
        {
            current = new AppContext()
            {
                ApppUser = user
            };
        }
    
        // call when a user logs out
        public static void Logout()
        {
            current = null;
        }
    
        // reference to the logged in user
        public AppUser User
        {
            get;
            private set;
        }
    
        public String FooString
        {
            get;
            set;
        }
    
        public int? FooInt
        {
            get;
            set;
        }
    
        public ComplexType FooClass
        {
            get;
            set;
        }
    
        public IList<Foo> ListOfFoo
        {
            get;
            set;
        }
    
        // ***** DEFINE ADDTL PARAMETERS HERE AS NEEDED *****
    }
    

    From any form in your application you could easily reference AppContext.Current. I am not sure if this quite answers your question, but this would be my first approach.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm using static class members so I can share data between class methods
Can someone share a simple example of using the foreach keyword with custom objects?
I am aware that I can share simple Objects using LocalConnection, but this does
I want to put sharing feature in my application so that i can share
i am integrating facebook with my iphone application. i can share text message in
I want to create an App that can share files between other iOS devices
I know that I can share files using Shared Folders in Virtual PC, but
Any one can share the mainfest.xml. How to set it? then can remove the
Can someone share their experiences with s#arp architecture. we have decided to follow mvp
Can anyone share? Excel format is fine too.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.