2011-01-09 77 views
0

我一直在使用一個外觀設計模式將我需要的所有行政功能組合在一起。接口和外觀設計模式

在我的類庫Company.Infrastructure.Repositories.Administration

我:

[Pluggable("Default")] 
    public class AdminRepository : IAdminRepository 
    { 

    #region private members 
    #endregion 

    #region protected members 
     protected Membership _membership; 
     protected Permissions _permissions; 
     protected Application _application; 
     protected Profile _profile; 
    #endregion 

     public AdminRepository() 
     { 
      _membership = new Membership(); 
      _permissions = new Permissions(); 
      _application = new Application(); 
      _profile = new Profile(); 
     } 

     protected class Profile 
     { 
      public Profile() {} 

      public void ProfileMethod1(){} 
      public void ProfileMethod2(){}  
     } 

     protected class Membership 
     { 
      public Membership() {} 
       public User GetUser(Guid id) 
     { 
      using (var dc = new My_SdbDataContext()) 
      { 
       var user = dc.aspnet_Users.Where(x => x.UserId == id).FirstOrDefault(); 
       var membership = dc.aspnet_Memberships.Where(x => x.UserId == id).FirstOrDefault(); 

       return Convert.ToEntity(user, membership); 

      } 
     } 

     public User GetUser(string userName) 
     { 
      using (var dc = new My_SdbDataContext()) 
      { 
       var user = dc.aspnet_Users.Where(x => x.UserName == userName).FirstOrDefault(); 
       var membership = dc.aspnet_Memberships.Where(x => x.UserId == user.UserId).FirstOrDefault(); 


       return Convert.ToEntity(user, membership); 

      } 
     } 

     public IEnumerable<User> GetUsers(Guid applicationId) 
     { 
      var userList = new List<User>(); 

      using (var dc = new My_SdbDataContext()) 
      { 
       var users = dc.aspnet_Users.Where(x => x.ApplicationId == applicationId).ToList<aspnet_User>(); 

       userList.AddRange((IEnumerable<User>) (from user in users 
               let membership = dc.aspnet_Memberships.Where(x => x.UserId == user.UserId).FirstOrDefault() 
               select Convert.ToEntity(user, membership))); 
      } 

      return userList; 
     } 
     } 

     etc... 


} 

這很適合我的工作。但是,我們已經轉移到DDD模型,並試圖找出如何繼續從WCF服務訪問我的AdminRepository(以前稱爲AdminFactory)。

爲了實現訪問,我已經在我的域邏輯中包含了我的Repository類的接口。但是,我不太清楚如何去創建一個Facade的界面,比如我有的界面(包括子類和全部)。這可能嗎?

我該怎麼做?

回答

1

我很困惑,爲什麼你想創建一個包含嵌套類的接口到你的AdminRepository。基於您的代碼,我想你會

public interface IAdminRepository 
{ 
    bool MemberHasPermission(int id) 
    //and so on - you didn't provide any methods, so I'm making one up 
    // ... 
} 

在這一點上,你IAdminRepository指定的合同,爲什麼會在合同中還規定了實施(在你的情況下受保護的嵌套類)?

請注意,這並不意味着我理解您使用受保護的嵌套類,或者爲什麼在所有抽象組件實際上都是內部實現時將其稱爲「門面模式」,或者爲什麼要將其轉換爲DDD模型很難從WCF訪問您的存儲庫。然而,我當然不明白爲什麼你會嘗試在接口中指定嵌套類,但是c#在任何情況下都不允許它(請注意,VB確實允許在接口中嵌套類型)。如果你想用這種方式指定契約,你可以使用抽象類而不用實現而不是接口,但是這會產生繼承問題。