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

  • Home
  • SEARCH
  • 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 51513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:45:44+00:00 2026-05-10T16:45:44+00:00

Imagine in the Global.asax.cs file I had an instance class as a private field.

  • 0

Imagine in the Global.asax.cs file I had an instance class as a private field. Let’s say like this:

private MyClass _myClass = new MyClass(); 

And I had a static method on Global called GetMyClass() that gets the current HttpApplication and returns that instance.

public static MyClass GetMyClass() {     return ((Global)HttpContext.Current.ApplicationInstance)._myClass; } 

So I could get the instance on the current requests httpapplication by calling Global.GetMyClass().

Keep in mind that there is more than one (Global) HttpApplication. There is an HttpApplication for each request and they are pooled/shared, so in the truest sense it is not a real singleton. But it does follow the pattern to a degree.

So as the question asked, would you consider this at the very least the singleton pattern?

Would you say it should not be used? Would you discourage its use? Would you say it’s a possibly bad practice like a true singleton.

Could you see any problems that may arise from this type of usage scenario?

Or would you say it’s not a true singleton, so it’s OK, and not bad practice. Would you recommend this as a semi-quasi singleton where an instance per request is required? If not what other pattern/suggestion would you use/give?

Have you ever used anything such as this?

I have used this on past projects, but I am unsure if it’s a practice I should stay away from. I have never had any issues in the past though.

Please give me your thoughts and opinions on this.

I am not asking what a singleton is. And I consider a singleton bad practice when used improperly which is in many many many cases. That is me. However, that is not what I am trying to discuss. I am trying to discuss THIS scenario I gave.

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-10T16:45:44+00:00Added an answer on May 10, 2026 at 4:45 pm

    Whether or not this fits the cookie-cutter pattern of a Singleton, it still suffers from the same problems as Singleton:

    • It is a static, concrete reference and cannot be substituted for separate behavior or stubbed/mocked during a test
    • You cannot subclass this and preserve this behavior, so it’s quite easy to circumvent the singleton nature of this example
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine a method like this ( in Win Forms): //First method private void buttonStart_Click(object
Imagine I have a property defined in global.asax. public List<string> Roles { get {
Imagine this: class A(object): class B(object): def __init__(self): super(B, self).__init__() This creates an error:
imagine that you had a task that finished in, say 10 seconds. Now, after
Let's say a user from a global site selects his/her country from a drop
A question about c++ design and efficiency... Imagine this code - Database db; class
Imagine we have a program trying to write to a particular file, but failing.
Imagine this directory structure: app/ __init__.py sub1/ __init__.py mod1.py sub2/ __init__.py mod2.py I'm coding
Imagine a system (Python) where the different parts constantly interact with one instance of
Imagine I have a set of global methods that aren't associated with any specific

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.