如标题描述的一样,在继承 ISoftDelete 后希望进行物理删除操作时,调用 HardDeleteAsync 方法即可。下面是该方法的内部实现:

public static async Task HardDeleteAsync<TEntity, TPrimaryKey>(this IRepository<TEntity, TPrimaryKey> repository, TEntity entity)
    where TEntity : class, IEntity<TPrimaryKey>, ISoftDelete
{
    var repo = ProxyHelper.UnProxy(repository) as IRepository<TEntity, TPrimaryKey>;
    if (repo == null)
    {
        throw new ArgumentException($"Given {nameof(repository)} is not inherited from {typeof(IRepository<TEntity, TPrimaryKey>).AssemblyQualifiedName}");
    }

    var items = ((IUnitOfWorkManagerAccessor)repo).UnitOfWorkManager.Current.Items;
    var hardDeleteEntities = items.GetOrAdd(UnitOfWorkExtensionDataTypes.HardDelete, () => new HashSet<string>()) as HashSet<string>;

    var tenantId = GetCurrentTenantIdOrNull(repo.GetIocResolver());
    var hardDeleteKey = EntityHelper.GetHardDeleteKey(entity, tenantId);

    hardDeleteEntities.Add(hardDeleteKey);

    await repo.DeleteAsync(entity);
}