Note that there are some explanatory texts on larger screens.

plurals
  1. POWould you consider this a singleton/singleton pattern?
    primarykey
    data
    text
    <p>Imagine in the Global.asax.cs file I had an instance class as a private field. Let's say like this:</p> <pre><code>private MyClass _myClass = new MyClass(); </code></pre> <p>And I had a static method on Global called GetMyClass() that gets the current HttpApplication and returns that instance.</p> <pre><code>public static MyClass GetMyClass() { return ((Global)HttpContext.Current.ApplicationInstance)._myClass; } </code></pre> <p>So I could get the instance on the current requests httpapplication by calling Global.GetMyClass().</p> <p>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 <a href="http://en.wikipedia.org/wiki/Singleton_pattern" rel="nofollow noreferrer">singleton</a>. But it does follow the pattern to a degree.</p> <p>So as the question asked, would you consider this at the very least the singleton pattern?</p> <p>Would you say it should not be used? Would you discourage its use? Would you say it's a <strong><em>possibly</em></strong> bad practice like a true singleton.</p> <p>Could you see any problems that may arise from this type of usage scenario?</p> <p>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?</p> <p>Have you ever used anything such as this?</p> <p>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.</p> <p>Please give me your thoughts and opinions on this.</p> <p>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.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload