山东雷驰
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.7 KiB

3 months ago
using Kean.Domain;
using Kean.Infrastructure.Database.Repository;
namespace Kean.Infrastructure.Repository
{
/// <summary>
/// 工作单元
/// </summary>
public sealed class UnitOfWork : IUnitOfWork
{
private readonly IDatabaseCollection _databaseCollection; // 数据库连接集合
/*
*
*
*/
public UnitOfWork(IDatabaseCollection databaseCollection)
{
_databaseCollection = databaseCollection;
}
/*
* Kean.Domain.IUnitOfWork.IsEntered
*/
public bool IsEntered { get; private set; }
/*
* Kean.Domain.IUnitOfWork.Enter
*/
public IUnitOfWork Enter()
{
IsEntered = true;
return this;
}
/*
* Kean.Domain.IUnitOfWork.Exit 退
*
*/
public IUnitOfWork Exit()
{
foreach (var item in _databaseCollection)
{
item.Save();
}
IsEntered = false;
return this;
}
/*
* System.IDisposable.Dispose
*
*/
public void Dispose()
{
foreach (var item in _databaseCollection)
{
item.Flush();
}
IsEntered = false;
}
}
}