Commit e01ef4cb authored by 阿星Plus's avatar 阿星Plus

🤩🤩🤩

parent 8455bd0b
namespace Plus.Domain.Uow
{
/// <summary>
/// Used to get/set current <see cref="IUnitOfWork"/>.
/// </summary>
public interface ICurrentUnitOfWorkProvider
{
/// <summary>
/// Gets/sets current <see cref="IUnitOfWork"/>.
/// Setting to null returns back to outer unit of work where possible.
/// </summary>
IUnitOfWork Current { get; set; }
}
}
\ No newline at end of file
namespace Plus.Domain.Uow
{
public interface IUnitOfWorkFilterExecuter
{
void ApplyDisableFilter(IUnitOfWork unitOfWork, string filterName);
void ApplyEnableFilter(IUnitOfWork unitOfWork, string filterName);
void ApplyFilterParameterValue(IUnitOfWork unitOfWork, string filterName, string parameterName, object value);
}
}
\ No newline at end of file
using System;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
namespace Plus.Domain.Uow
{
/// <summary>
/// This handle is used for innet unit of work scopes.
/// A inner unit of work scope actually uses outer unit of work scope
/// and has no effect on <see cref="IUnitOfWorkCompleteHandle.Complete"/> call.
/// But if it's not called, an exception is thrown at end of the UOW to rollback the UOW.
/// </summary>
internal class InnerUnitOfWorkCompleteHandle : IUnitOfWorkCompleteHandle, IDisposable
{
public const string DidNotCallCompleteMethodExceptionMessage = "未调用完整方法的工作单元";
private volatile bool _isCompleteCalled;
private volatile bool _isDisposed;
public void Complete()
{
_isCompleteCalled = true;
}
public Task CompleteAsync()
{
_isCompleteCalled = true;
return Task.FromResult(0);
}
public void Dispose()
{
if (_isDisposed)
{
return;
}
_isDisposed = true;
if (!_isCompleteCalled)
{
if (HasException())
{
return;
}
throw new PlusException(DidNotCallCompleteMethodExceptionMessage);
}
}
private static bool HasException()
{
try
{
return Marshal.GetExceptionCode() != 0;
}
catch (Exception)
{
return false;
}
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment