0

I am looking at the code presented in this SO answer https://stackoverflow.com/a/4243338/223742.

The code works exactly as advertised but what I don't understand is how the singleton is storing its static members across requests e.g:

private static string host = null;

Is it by virtue of the fact that the FirstRequestInitialisation class is static that it is saving it in the storage for the app?

Community
  • 1
  • 1
TheEdge
  • 9,291
  • 15
  • 67
  • 135

1 Answers1

0

Your assertion that it is because the FirstRequestInitialisation class is static is correct. Being a static class, it remains in memory for the lifetime of the application domain in which your program resides. This means whenever the 'FirstRequestInitialisation` class is referenced, the same instance is returned across the application, in the same way a static member is shared across all instances of the parent type.

See Static Classes and Static Methods article on the MSDN for more info.

Adrian Sanguineti
  • 2,455
  • 1
  • 27
  • 29