Concurrency Question

  • Thread starter Thread starter Nick
  • Start date Start date
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?
 
I've bounced this around a few other folk. This approach should work as
expected. Your assumptions are correct. If you experience issues, feel free
to repost.
 
Alvin,

Thanks for the reply and for bouncing the ideas. I am working on the
assumption all is as expected, but I will be writing a pukka set of
acceptance tests for this at some point to confirm.

Cheers.

Alvin Bruney said:
I've bounced this around a few other folk. This approach should work as
expected. Your assumptions are correct. If you experience issues, feel free
to repost.

--
Regards,
Alvin Bruney
[ASP.NET MVP http://mvp.support.microsoft.com/default.aspx]
Got tidbits? Get it here... http://tinyurl.com/27cok
Nick said:
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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top