N
Nick
I have a Registry class in a layer below the UI/Web layer. Inside it has a
static member which points to an instance of IRegistry. When the web app
starts, I set this instance member to a class written in the ui layer. Lets
suppose IRegistry has a single method on it, called GetUsername():
public interface IRegistry
{
string GetUsername();
}
My class in the ui would do the following:
public class UIRegistry : IRegistry
{
public UIRegistry(){
}
public string GetUsername(){
return (string)HttpContext.Current.Session["username"];
}
}
Registry is implemented like:
public class Registry
{
private static IRegistry _registryImpl;
public Registry() { }
public static Initialize(IRegistry registryImpl);
public string GetUsername(){
return _registryImpl.GetUsername();
}
}
Pretty simple stuff. I am treating the Session as the Registry for things I
need to store (UIRegistry). Now, as far as I understand it, GetUsername in
the UIRegistry class will work as expected, even if multiple threads follow
the same call chain to GetUsername. I am wondering if someone knows if I
have overlooked something in this area. It seems sound to expect
HttpContext.Current to always be relevant to the current thread of
execution. I want to make sure this is a correct assumption, because when I
put Set methods on the Registry object, and want to make sure the correct
Session is updated.
Anyone got any thoughts on this?
static member which points to an instance of IRegistry. When the web app
starts, I set this instance member to a class written in the ui layer. Lets
suppose IRegistry has a single method on it, called GetUsername():
public interface IRegistry
{
string GetUsername();
}
My class in the ui would do the following:
public class UIRegistry : IRegistry
{
public UIRegistry(){
}
public string GetUsername(){
return (string)HttpContext.Current.Session["username"];
}
}
Registry is implemented like:
public class Registry
{
private static IRegistry _registryImpl;
public Registry() { }
public static Initialize(IRegistry registryImpl);
public string GetUsername(){
return _registryImpl.GetUsername();
}
}
Pretty simple stuff. I am treating the Session as the Registry for things I
need to store (UIRegistry). Now, as far as I understand it, GetUsername in
the UIRegistry class will work as expected, even if multiple threads follow
the same call chain to GetUsername. I am wondering if someone knows if I
have overlooked something in this area. It seems sound to expect
HttpContext.Current to always be relevant to the current thread of
execution. I want to make sure this is a correct assumption, because when I
put Set methods on the Registry object, and want to make sure the correct
Session is updated.
Anyone got any thoughts on this?