Beispiel #1
0
        /// <summary>
        /// Api调用结束后释放资源,提交或回滚事务、关闭数据库连接、发布领域事件
        /// </summary>
        /// <param name="p_suc"></param>
        /// <returns></returns>
        internal async Task Close(bool p_suc)
        {
            await _db.Close(p_suc);

            // 发布领域事件
            if (p_suc && _domainEvents != null)
            {
                var localEB  = Kit.GetObj <LocalEventBus>();
                var remoteEB = Kit.GetObj <RemoteEventBus>();
                foreach (var de in _domainEvents)
                {
                    if (de.IsRemoteEvent)
                    {
                        remoteEB.Broadcast(de.Event, false);
                    }
                    else
                    {
                        localEB.Publish(de.Event);
                    }
                }
            }
            _domainEvents?.Clear();
        }