English 中文(简体)
如何正确获取本领域数据模型假设中的参考数据?
原标题:What s the correct way of accessing reference data in this Domain Data Modelling scenario?

www.un.org/Depts/DGACM/index_french.htm

鉴于客户分类的开始程度如下:

public class Customer : KeyedObject
{

   public Customer(int customerId)
   {
      _customerRepository.Load(this);
   }

   private ICustomerRepository _customerRepository = IoC.Resolve(..);  
   private ICustomerTypeRepository = _customerTypeRepository = IoC.Resolve(..);

   public virtual string CustomerName {get;set;}
   public virtual int CustomerTypeId [get;set;}

   public virtual string CustomerType
   {
      get
      {
         return _customerTypeRepository.Get(CustomerTypeId);
      }
   }

}

客户 类型以价值物体表示:

public class CustomerType : ValueObject
{
   public virtual int CustomerTypeId {get;set;}
   public virtual string Description {get;set;}
}

当我有客户物体时,这完全是好的。 然而,当我想要在我的MVC中安置一名DonList。 我认为,我对如何正确从ICustomerTypeRepostory中获取客户价值清单的概念进行了斗争。

<编码>ICustomerTypeRepository 非常简单:

public interface ICustomerTypeRepository
{
   public CustomerType Get(int customerTypeId);
   public IEnumerable<CustomerType> GetList();
}

基本上,我希望能够打电话<代码>。 然而,我认为最好把DAL(保存人)的层面与控制者分开。 现在,我是否刚刚克服重复的问题?

这正是我的控制者目前的状况:

public class CustomerController : ControllerBase
{ 

    private ICustomerTypeRepository _customerTypeRepository = IoC.Resolve(..);

    public ActionResult Index()
    {
       Customer customer = new Customer(customerId); 
       IEnumerable<CustomerType> customerTypeList = 
          _customerTypeRepository.GetList();

       CustomerFormModel model = new CustomerFormModel(customer);
       model.AddCustomerTypes(customerTypeList );
    }
}

这对我来说似乎是错的,因为我在主计长和客户中盘点。 在我看来,客户Type的进入层应该eg然.。 页: 1

public class CustomerType : ValueObject
{
   // ... Previous Code

   private static ICustomerTypeRepository _customerTypeRepository = IoC.Resolve(..);

   public static IEnumerable<CustomerType> GetList()
   {
      _customerTypeRepository.GetList();
   }
}

因此,这是我should。 将<编码>CustomerType的物体通过<编码>ICustomerTypeRepository至CustomerController?

最佳回答

我认为这里有几个问题需要考虑。

首先,如果你真心想模仿你的领域,那么你就想以一切代价努力使各域实体自己不受交叉问题的影响,例如,验证、电离层集装箱和持久性,尽管有积极的记录模式。

这意味着:<代码> 客户可能不应提及一个存放处,即使你利用接口和服务定位器进行搬迁。 其目的应从目标客户/用户的角度反映——或构成——“客户”的属性。

除域网外,我对使用您的<代码>IoC服务定位器在一种可变的初始器中的使用感到担忧。 你丧失了任何机会来追捕建筑商提出的例外和例外,令人难以解冻(这些最初的施工者在你第一个非统计建筑商的任何法典之前就跑过了)。

使用静态网关/服务定位器取代注射依赖性,也使这一类几乎无法测试(使用自动单位测试方法,即:你可以进行整合和手工测试,但测试失败不可能把你指破碎的借方——而不是单位测试,因为你知道你正在测试的一件事,因此打碎了什么。

申请不是通过在施工人中打上<代码>_customer Repository.Load(this)而填满数据,而是将更一般地利用储存库来接收该实体,因此从全员居住的存放处收回,包括CustomerType。 在本案中,看来这可能发生在<代码>上。 客户密码。

您表示,您希望将DAL与<代码>的层分开。 客户控制器有,而且你确实有——这是在使用储存接口的地方。 您将~em>落实这一接口(或在此情况下,从IoC的实施工作中获得执行),但该储存库的实际实施情况可以在一个单独的层次上存在(甚至可能是另一个组)。 这是一种称为单独接口的模式。

我个人希望客户主计长也这样做:

public class CustomerController : ControllerBase
{ 
     private ICustomerTypeRepository _customerTypeRepository;
     private ICustomerRepository _customerRepository;

     public CustomerController(ICustomerRepository customerRepository,
        ICustomerTypeRepository customerTypeRepository)
     {
        _customerRepository = customerRepository;
        _customerTypeRepository = customerTypeRepository;
     }

     public ActionResult Index()
     {
         Customer customer 
             = _customerRepository.GetCustomerWithId(customerId); 
             // from where does customerId come?

         IEnumerable<CustomerType> customerTypeList 
             = _customerTypeRepository.GetTypes();

        . . .

     }
}

页: 1

问题回答

如何改变客户领域模式,将客户财产包括在内? 这也将不再需要在客户电话时打到存放处。

public class Customer : KeyedObject
{

   public Customer(int customerId)
   {
      _customerRepository.Load(this);

      ICustomerTypeRepository _customerTypeRepository = IoC.Resolve(..);
      _customerTypes = _customerTypeRepository.GetList();
   }

   private ICustomerRepository _customerRepository = IoC.Resolve(..);  

   public virtual string CustomerName {get;set;}
   public virtual int CustomerTypeId {get;set;}

   public virtual string CustomerType
   {
      get
      {
         return _customerTypes.Find(CustomerTypeId);
      }
   }

   private IEnumerable<CustomerType> _customerTypes;
   public virtual IEnumerable<CustomerType> CustomerTypes
   {
      get
      {
          return _customerTypes
      }
   }
}




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...