TableProfileProviderを使用して、n層アーキテクチャでASP.NETプロファイルシステムを使用しています。
UIレイヤーはWebアプリケーションであるため、プロファイルを使用できるようにするには、profilecommonクラスを公開する必要があります。
これが私のアーキテクチャの単純化されたスキーマです:
UI: ASP.NETWebアプリケーション。
BusinessEntities:純粋なPOCOクラス。パーシスタンスイグロナス。
BLL:ビジネスロジック層。
DAL:データアクセス層。
Profilecommonの定義は次のとおりです。
public class ProfileCommon : ProfileBase
{
public virtual ProfileCommon GetProfile(string username)
{
return (ProfileCommon)ProfileBase.Create(username);
}
public virtual string FirstName
{
get
{
return (string)base.GetPropertyValue("FirstName");
}
set
{
base.SetPropertyValue("FirstName", value);
}
}
}
すべてがWebアプリケーションプロジェクトで定義されている単純な設計アーキテクチャでは、次のようにprofilecommonにアクセスします
。ProfileCommonstrongleyTypedProfile =(ProfileCommon)this.Context.Profile;
ビジネスロジックレイヤーからプロファイルコモンにアクセスできるようにしたいので、ProfileCommon定義をBusinessEntitiesライブラリに移動し(BusinessEntitiesライブラリにSystem.Webアセンブリへの参照を追加する必要がありました)、新しいProfileBLLクラスを定義しました。
public class ProfileInfo
{
public ProfileInfo(ProfileCommon profile)
{
this.Profile = profile;
}
public ProfileCommon Profile { get; set; }
public string GetFullName()
{
return this.Profile.FirstName + " " + this.Profile.LastName;
}
}
これで、次のようにUIから共通のプロファイルにアクセスできます。
var profileInfo = new BLL.ProfileInfo((ProfileCommon)this.Context.Profile);
txtFullName.text = profileInfo.GetFullName();
さて、Business Layer / BusinessEntities LibraryでSystem.Webを参照することは、n層アーキテクチャの分野に違反していますか?もしそうなら、これを達成するためにあなたは何を提案しますか?