理論的には、人々はそれが悪いビジネス慣行だと言うでしょう。実際には、ビジネス層で常に利用可能なセッション レベルからのデータが必要でした。:-(
最終的に、小さなインターフェイスの下にさまざまなストレージ エンジンを統合することになりました。
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; }
}
}
アプリケーションを開始すると、ウェブサイトは
Framework.Storage.SessionStorage = new WebSessionStorage();
Global.asax で、FormsApp が行います
Framework.Storage.SessionStorage = new WebFormsSessionStorage();