仓库边界

问题描述

| 假设应用程序在存储库接口,实现库和BLL(BPL)中具有Business Objects库,那么您如何确定需要与存储库耦合的内容以及直接与BPL关联的内容 BOs.dll ISomeObjectRepository.cs
public interface ISomeObjectRepository:  
IRepository<SomeObject>,ILazyFetchingRepository<SomeObject>  
{  
      SomeObject GetSomeObjectByWeirdFields(IDictionary<string,object> weirdFields);  
} 
Repositories.dll SomeObjectRepository.cs
public sealed class SomeObjectRepository:  
BaseRepository<SomeObject>,ISomeObjectRepository  
{  
     public SomeObject GetSomeObjectByWeirdFields(IDictionary<string,object> weirdFields){  
         throw new NotImplementedException();  
        }  
}
BPL.dll SomeObjectService.cs
public static class SomeObjectService:  
{  
     public static SomeObject GetSomeObjectByWeirdFields(IDictionary<string,object> weirdFields){  
           throw new NotImplementedException();  
     }  
} 
所以问题确实是,谁的责任是GetSomeObjectByWeirdFields实现?欢迎提供任何模式指南。     

解决方法

        如您所提到的,存储库接口存在于域层(业务层)中,该接口定义了抽象合约的合同,该合约在域模型中进行了抽象。 服务层取决于存储库(ISomeObjectRepository)的抽象,对具体实现一无所知。 关于在何处实施具体存储库的问题的答案,应该在较低的层中进行定义,该层可以称为数据访问层,技术服务层或持久性层,无论您将其称为什么,重要的是实现它在不同的组件中,可以在不影响所有其他层也不影响存储库接口的情况下替换此组件。例如,您可以使用NHibernate来实现您的存储库,稍后您可以决定将其替换为Entity Framework实现,Ado甚至xml文件。 问题是,存储库的具体实现应分开属于技术服务或数据访问的另一个组件。 请访问http://sellandbuy.codeplex.com/,以在单独的层中使用NHibernate获取存储库的示例实现。