It looks like it should work.
The lock in the GetCurrent method is totally useless, though. As you are
locking using an object that you created on the previous line, it has no
effect what so ever.
I plan to use the object in different code files. For e.g.
In my default.aspx page's code behind (which is actually a derived
page) I plan to write code like this:
LabelUserID.Text = UserInfo.GetCurrent().UserID.ToString(); //Line A
And, then in my master page's (say master.master, the default.aspx
derives from this) code behind I plan to do something like this:
LabelLoggedIn.Text = "Logged in as " + UserInfo.GetCurrent
().Username; //Line B
Now consider one thread processing default.aspx. It will process
routines in this page first; so when line A gets executed, the
singleton is called for the first time, and the instance get stored to
the httpcontext, and that is returned to us. Processing goes on. The
master page's routines are processed next. So when line B is executed
we get the stored instance to use.
Now, what if two or more users are concurrently requesting this page?
Will there be any conflict?
--deostroll