2011-01-25 2 views
1

n 계층 아키텍처에서 ASP.NET 프로필 시스템을 사용하려면 TableProfileProvider를 사용하고 있습니다.
UI 레이어는 웹 응용 프로그램이므로 프로필을 사용할 수 있으려면 profilecommon 클래스를 노출해야합니다.
다음은 내 아키텍처의 간단한 스키마입니다.
UI : ASP.NET 웹 응용 프로그램.
BusinessEntities : 순수 POCO 클래스. 지속성 Igronace.
BLL : 비즈니스 로직 계층.
DAL : 데이터 액세스 계층.n 계층 구조의 비즈니스 로직 계층에 System.Web 참조 추가

Profilecommon 정의는 다음과 같습니다
ProfileCommon strongleyTypedProfile = (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); 
     } 
    } 
} 

, 내가 profilecommon에 액세스하는 것입니다. 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(); 

를 이제 비즈니스 계층에 System.Web을 참조하는/BusinessEntities 도서관은 n 계층 아키텍처 분야를 위반? 그렇다면이 목표를 달성하기 위해 무엇을 제안 하시겠습니까?

+0

@skaffman를 사용하여 웹 어플리케이션에서 IProfile 인터페이스를 구현하는 자유가없는 말할 수 있습니다 :이 n 계층 관련 질문이 아닙니다. 이것은 n-layer와 관련이 있습니다. n-tier는 하드웨어 수준에서 별도의 레이어가있는 경우를 의미합니다. – Kamyar

답변

1

대신 인터페이스를 구현하여 ProfileBase에 대한 종속성을 깨뜨릴 수 있습니다. 이제

public interface IProfile 
{ 
    string FirstName { get; set; } 
    string LastName { get; set; } 

    IProfile GetProfile(string username); 
} 

public class ProfileCommon : ProfileBase, IProfile 
{ 
    public virtual IProfile GetProfile(string username) 
    { 
     return (ProfileCommon)ProfileBase.Create(username); 
    } 

    public virtual string FirstName 
    { 
     get 
     { 
      return (string)base.GetPropertyValue("FirstName"); 
     } 
     set 
     { 
      base.SetPropertyValue("FirstName", value); 
     } 
    } 
} 

public class ProfileInfo 
{ 
    public ProfileInfo(IProfile profile) 
    { 
     this.Profile = profile; 
    } 

    public IProfile Profile { get; set; } 

    public string GetFullName() 
    { 
     return this.Profile.FirstName + " " + this.Profile.LastName; 
    } 
} 

당신이 당신의 비즈니스 로직에를 System.Web.dll에 대한 종속성을 가지고 있지만 여전히 ProfileBase

+0

추상화 및 느슨한 결합에 대한 탁월한 이해. 고맙습니다. – Kamyar

1

비즈니스 계층에서 System.Web에 액세스하면 안됩니다. 이는 웹 애플리케이션으로 작업하는 것과 관련이 있습니다. 다른 종류의 응용 프로그램에서 비즈니스 계층을 재사용하고 싶다면 어떻게해야할까요?

당신은 당신이 이것을 통해 무엇을 성취하려고하는지 스스로 자문해야합니다. 그런 다음 해당 요구 사항을 비즈니스 계층이 액세스하기에 적합한 일반적인 것으로 추상화하십시오. 이것은 비즈니스 계층이 사용자에 대해 전혀 알고 있어야한다고 가정합니다.

관련 문제