As Igor notes , one option is to use dependency forwarding plus parameter passing, so that your global variable is available for everything that needs it.
But if you really want to use the static property, you can use the HttpContext.Items property to store temporary data related to the simple current request:
public class App
{
public static IUser User
{
get { return (IUser)HttpContext.Current.Items["User"]; }
set { HttpContext.Current.Items["User"] = value; }
}
}
The third option (which I do not recommend) is to use a static field supported by the ThreadStatic attribute :
public class App
{
[ThreadStatic]
private static IUser user;
public static IUser User
{
get { return user; }
set { user = value; }
}
}
This option has the advantage that it has no dependencies on System.Web. However, it is only valid if your controller is synchronous, and it will break if you ever use it async.