public static async Task DispatchDomainEventsAsync(this IMediator mediator, AppUnitofWork ctx)
        {
            var domainEntities = ctx.ChangeTracker
                                 .Entries <Entity>()
                                 .Where(x => x.Entity.DomainEvents != null && x.Entity.DomainEvents.Any());

            var domainEvents = domainEntities
                               .SelectMany(x => x.Entity.DomainEvents)
                               .ToList();

            domainEntities.ToList()
            .ForEach(entity => entity.Entity.ClearDomainEvents());

            var tasks = domainEvents
                        .Select(async(domainEvent) =>
            {
                await mediator.Publish(domainEvent);
            });

            await Task.WhenAll(tasks);
        }
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="unitofWork"></param>
 public BaseRepository(AppUnitofWork unitofWork)
 {
     this._unitofWork = unitofWork;
 }