tangxuehua / enode

ENode is a framework aims to help us developing ddd, cqrs, eda, and event sourcing style applications.
http://www.cnblogs.com/netfocus/category/496012.html
MIT License
1.81k stars 564 forks source link

CommandHandler增加异步处理方式 #73

Closed Caskia closed 5 years ago

Caskia commented 6 years ago

由于CQRS系统无法根据字段对聚合根查询,在CommandHandler中有时候为了判断数据的唯一性,免不了会做一些访问IO资源的操作,例如调用分布式锁,所以希望能够增加异步的handler处理方法。

            _lockService.ExecuteInLock(typeof(RecommendNameIndex).Name, () =>
            {
                var recommend = new Recommend(command.AggregateRootId, command.CreatorUserId, new RecommendInfo()
                {
                    ContentType = command.ContentType.To<Content.ContentType>(),
                    Name = command.Name,
                    Description = command.Description
                });

                _recommendService.CreateRecommendNameIndex(command.AggregateRootId, command.ContentType.To<Content.ContentType>(), command.Name);

                context.Add(recommend);
            });
tangxuehua commented 5 years ago

已支持异步Command Handler