思考一种好的架构(十二)

 

事件溯源(TracingSource)

 

 /// <summary>
    /// 数据库事件溯源实体
    /// </summary>
    [Table(name: "TracingSource")]
   public class TracingSourceEntity
    {
        [ColumnAttribute(IsPrimaryKey =true)]
        [AutoIncrement]
        public int ID { get; set; }
        /// <summary>
        /// 执行时间
        /// </summary>
        public DateTime ExecuteTimer { get; set; }

        /// <summary>
        /// 执行Sql
        /// </summary>
        public string ExecuteSql { get; set; }
    }

 

  class DCCQRSCommandEventHandler : INotificationHandler<DCCQRSCommandEvent>
    {
        IDbContext DC;
        IMapper Mapper;
        public DCCQRSCommandEventHandler(IDbContext DC,IMapper Mapper) {
            this.DC = DC;
            this.Mapper = Mapper;
        }

        public Task Handle(DCCQRSCommandEvent notification, CancellationToken cancellationToken)
        {
            DC.Insert(Mapper.Map<TracingSourceEntity>(notification));
            return Task.CompletedTask;
        }
    }

 

class StartExecute : BaseStartExecute
    {
        public override void Execute()
        {
            EventBusPost.CreateEvent(typeof(Startup));
            MapperPost.CreateMap(x =>
                x.CreateMap<DCCQRSCommandEvent, TracingSourceEntity>().ForMember(dest => dest.ID, opt => opt.Ignore())
            );
        }
    }

    public static class Startup
    {
        public static void ConfigureServices(IServiceCollection services)
        {
          
        }

        public static void Configure(IApplicationBuilder app, IHostingEnvironment env)
        {
         
        }
    }

 

事件溯源服务的问题

  1、没有数据回溯功能,充其量也只是一个事件持久化

  2、使用业务库,而不是NoSql

解释

  1、懒

  2、虽然它使用了业务库,但是还是一个归类为普通服务,使用业务库做持久化只是暂时的

posted @ 2020-04-01 14:28  AnAng  阅读(190)  评论(0编辑  收藏  举报