理论上人们会告诉你它是一个不好的商业惯例。 实际上,我们只需要来自业务层中可用的会话级别的数据。 :-(
我们最后不得不下有小的接口统一不同的存储引擎。
public interface ISessionStorage
{
SomeSessionData Data {get;set;}
...
.. and most of the data we need stored at "session" level
}
//and a singleton to access it
public static ISessionStorage ISessionStorage;
此接口可从我们的代码几乎任何地方。
然后我们有两个会话和/或一个单独实施
public WebSessionStorage
{
public SomeSessionData Data
{
get { return HttpContext.Current.Session["somekey"] as SomeSessionData;}
set { HttpContext.Current.Session["somekey"] = value;}
}
public WebFormsSessionStorage
{
private static SomeSessionData _SomeSessionData; //this was before automatic get;set;
public SomeSessionData
{
get{ return _SomeSessionData;}
set{ _SomeSessionData=value; }
}
}
在INITING的应用程序,网站将做在Global.asax中一个
Framework.Storage.SessionStorage = new WebSessionStorage();
,和FormsApp将做
Framework.Storage.SessionStorage = new WebFormsSessionStorage();