zoukankan      html  css  js  c++  java
  • Software--电商平台--Module 5 Order & Payment

    2018-01-10  14:11:30

    电商平台 订购和支付 模块

    一: 整体示意图

    二:构建一个框架来处理 领域模型内部发生的事情--领域事件

    1. IDomainEvent 标识模型中的 DomainEvent
    2. IDomainEventHandler<T> where T : IDomainEvent 事件处理程序必须实现的接口。
    3. IDomainEventHandlerFactory 用来获取给定领域事件的处理程序的集合
    4. IEnumerableExtension 获取到 IDomainEventHandler 集合之后, 调用它们的处理方法并将领域事件作为动作的实参。
      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      
      namespace Agathas.Storefront.Infrastructure.Domain.Events
      {
          public static class IEnumerableExtensions
          {
              public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
              {
                  foreach (T item in source)
                      action(item);
              }
          }
      
      }
    5. 静态类 DomainEvents -- 为了引发事件。

      支持领域事件所需的框架。

      

     

    二 : 领域对象 

    1. Payment  值对象, 继承自 Infrastructure  -- ValueObjectBase    
    2. OrderItem 实体  继承自 EntityBase<int> 
    3. 与OrderItem 相关联的 Order 

    EntityBase<int>

    using System.Collections.Generic;
    
    namespace Agathas.Storefront.Infrastructure.Domain
    {
        public abstract class EntityBase<TId>
        {
            private List<BusinessRule> _brokenRules = new List<BusinessRule>();
    
            public TId Id { get; set; }
    
            protected abstract void Validate();
    
            public IEnumerable<BusinessRule> GetBrokenRules()
            {
                _brokenRules.Clear();
                Validate();
                return _brokenRules;
            }
    
            protected void AddBrokenRule(BusinessRule businessRule)
            {
                _brokenRules.Add(businessRule);
            }
    
            public override bool Equals(object entity)
            {
                return entity != null
                   && entity is EntityBase<TId>
                   && this == (EntityBase<TId>)entity;
            }
    
            public override int GetHashCode()
            {
                return this.Id.GetHashCode();
            }
    
            public static bool operator ==(EntityBase<TId> entity1,
               EntityBase<TId> entity2)
            {
                if ((object)entity1 == null && (object)entity2 == null)
                {
                    return true;
                }
    
                if ((object)entity1 == null || (object)entity2 == null)
                {
                    return false;
                }
    
                if (entity1.Id.ToString() == entity2.Id.ToString())
                {
                    return true;
                }
    
                return false;
            }
    
            public static bool operator !=(EntityBase<TId> entity1,
                EntityBase<TId> entity2)
            {
                return (!(entity1 == entity2));
            }
        }
    
    }

    ValueObjectBase

    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace Agathas.Storefront.Infrastructure.Domain
    {
        public abstract class ValueObjectBase
        {
            private List<BusinessRule> _brokenRules = new List<BusinessRule>();
    
            public ValueObjectBase()
            {
            }
    
            protected abstract void Validate();
    
            public void ThrowExceptionIfInvalid()
            {
                _brokenRules.Clear();
                Validate();
                if (_brokenRules.Count() > 0)
                {
                    StringBuilder issues = new StringBuilder();
                    foreach (BusinessRule businessRule in _brokenRules)
                        issues.AppendLine(businessRule.Rule);
    
                    throw new ValueObjectIsInvalidException(issues.ToString());
                }
            }
    
            protected void AddBrokenRule(BusinessRule businessRule)
            {
                _brokenRules.Add(businessRule);
            }
        }
    }

       

  • 相关阅读:
    【MySQL】MySQL主从库配置和主库宕机解决方案
    【MySQL】局域网内:在一台电脑访问另一台电脑的mysql数据库
    【TP5.0】tp5.0实现连接多个数据库,实现类似3.2M(‘table’,'prefix_','db_config2')的CURD操作
    【转载】Mysql主从复制、和MySQL集群(主主复制)
    (转载)【TP5.0】设置session有效时长+修改默认存储路径
    【php+js】用PHP或者JS怎么显示搜索到的关键字高亮,及其文章里包含关键字的一小段
    【Mysql】php执行脚本进行mysql数据库 备份和还原
    【jquery】ajax 动态 改变 select下拉框选中的值
    【TP5.0】model的操作方法
    【php导出pdf文件】php将html 导出成pdf文件(MPDF60),支持完美分页,注意是完美!!
  • 原文地址:https://www.cnblogs.com/masterSoul/p/8258475.html
Copyright © 2011-2022 走看看