完成工作单元模块

This commit is contained in:
橙子
2023-01-17 23:33:14 +08:00
parent da2cf2acc5
commit 2fa3570f85
11 changed files with 134 additions and 102 deletions

View File

@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Uow
{
public interface IUnitOfWork : IDisposable
{
bool IsTran { get; set; }
bool IsCommit { get; set; }
bool IsClose { get; set; }
bool Commit();
}
}

View File

@@ -1,94 +1,8 @@
//namespace Yi.Framework.Uow
//{
// public interface IUnitOfWorkManager
// {
// SugarUnitOfWork CreateContext(bool isTran = true);
// }
namespace Yi.Framework.Uow
{
public interface IUnitOfWorkManager
{
IUnitOfWork CreateContext(bool isTran = true);
}
// /// <summary>
// /// 这个放到实现类中
// /// </summary>
// public class SugarUnitOfWorkManager : IUnitOfWorkManager
// {
// public SugarUnitOfWorkManager(ISqlSugarClient db)
// {
// this.Db = db;
// }
// public SugarUnitOfWork Db { get; set; }
// public SugarUnitOfWork CreateContext(bool isTran = true)
// {
// return Db.CreateContext(isTran);
// }
// }
// /// <summary>
// /// 下面这个定死了
// /// </summary>
// public class SugarUnitOfWork : IDisposable
// {
// public ISqlSugarClient Db { get; internal set; }
// public ITenant Tenant { get; internal set; }
// public bool IsTran { get; internal set; }
// public bool IsCommit { get; internal set; }
// public bool IsClose { get; internal set; }
// public void Dispose()
// {
// if (this.IsTran && IsCommit == false)
// {
// this.Tenant.RollbackTran();
// }
// if (this.Db.Ado.Transaction == null && IsClose == false)
// {
// this.Db.Close();
// }
// }
// public SimpleClient<T> GetRepository<T>() where T : class, new()
// {
// TenantAttribute tenantAttribute = typeof(T).GetCustomAttribute<TenantAttribute>();
// if (tenantAttribute == null)
// {
// return new SimpleClient<T>(Db);
// }
// else
// {
// return new SimpleClient<T>(Db.AsTenant().GetConnection(tenantAttribute.configId));
// }
// }
// public RepositoryType GetMyRepository<RepositoryType>() where RepositoryType : ISugarRepository, new()
// {
// var result = new RepositoryType();
// var type = typeof(RepositoryType).GetGenericArguments()[0];
// TenantAttribute tenantAttribute = type.GetCustomAttribute<TenantAttribute>();
// if (tenantAttribute == null)
// {
// result.Context = this.Db;
// }
// else
// {
// result.Context = this.Db.AsTenant().GetConnection(tenantAttribute.configId);
// }
// return result;
// }
// public bool Commit()
// {
// if (this.IsTran && this.IsCommit == false)
// {
// this.Tenant.CommitTran();
// IsCommit = true;
// }
// if (this.Db.Ado.Transaction == null && this.IsClose == false)
// {
// this.Db.Close();
// IsClose = true;
// }
// return IsCommit;
// }
// }
//}
}