删除多余文件

This commit is contained in:
橙子
2023-01-02 21:18:38 +08:00
parent 714d1a36c4
commit 762c455b53
8 changed files with 0 additions and 311 deletions

View File

@@ -1,13 +0,0 @@
using System.Data;
namespace Yi.Framework.Uow
{
public interface IUnitOfWork : IDisposable
{
public void Init(bool isTransactional, IsolationLevel? isolationLevel, int? timeout);
public void BeginTran();
public void CommitTran();
public void RollbackTran();
}
}

View File

@@ -1,44 +0,0 @@
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Uow.Interceptors
{
public class UnitOfWorkAttribute : Attribute// : AbstractInterceptorAttribute
{
public UnitOfWorkAttribute(bool isTransactional = true)
{
IsTransactional = isTransactional;
}
public UnitOfWorkAttribute(IsolationLevel isolationLevel, bool isTransactional = true) : this(isTransactional)
{
IsolationLevel = isolationLevel;
}
public UnitOfWorkAttribute(IsolationLevel isolationLevel, int timeout, bool isTransactional = true) : this(isolationLevel, isTransactional)
{
Timeout = timeout;
}
public bool IsTransactional { get; }
public IsolationLevel? IsolationLevel { get; }
/// <summary>
/// Milliseconds
/// </summary>
public int? Timeout { get; }
public bool IsDisabled { get; }
//public override Task Invoke(AspectContext context, AspectDelegate next)
//{
// if (IsTransactional)
// {
// ServiceLocator.in.getservice()
// }
//}
}
}

View File

@@ -1,78 +0,0 @@
using Castle.DynamicProxy;
using Nest;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Uow.Interceptors
{
public class UnitOfWorkInterceptor : IInterceptor
{
private readonly IUnitOfWork _unitOfWork;
public UnitOfWorkInterceptor(IUnitOfWork unitOfWork)
{
_unitOfWork = unitOfWork;
}
public void Intercept(IInvocation invocation)
{
if (!IsUnitOfWorkMethod(invocation.Method, out var uowAttr))
{
invocation.Proceed();
return;
}
try
{
_unitOfWork.BeginTran();
//执行被拦截的方法
invocation.Proceed();
_unitOfWork.CommitTran();
}
catch (Exception ex)
{
_unitOfWork.RollbackTran();
throw ex;
}
}
public static bool IsUnitOfWorkMethod( MethodInfo methodInfo,out UnitOfWorkAttribute unitOfWorkAttribute)
{
//Method declaration
var attrs = methodInfo.GetCustomAttributes(true).OfType<UnitOfWorkAttribute>().ToArray();
if (attrs.Any())
{
unitOfWorkAttribute = attrs.First();
return !unitOfWorkAttribute.IsDisabled;
}
if (methodInfo.DeclaringType != null)
{
//Class declaration
attrs = methodInfo.DeclaringType.GetTypeInfo().GetCustomAttributes(true).OfType<UnitOfWorkAttribute>().ToArray();
if (attrs.Any())
{
unitOfWorkAttribute = attrs.First();
return !unitOfWorkAttribute.IsDisabled;
}
////Conventional classes
//if (typeof(IUnitOfWorkEnabled).GetTypeInfo().IsAssignableFrom(methodInfo.DeclaringType))
//{
// unitOfWorkAttribute = null;
// return true;
//}
}
unitOfWorkAttribute = null;
return false;
}
}
}

View File

@@ -1,21 +0,0 @@
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yi.Framework.Uow;
using Yi.Framework.Uow.Interceptors;
namespace Microsoft.Extensions.DependencyInjection
{
public static class UowIServiceCollectionExtensions
{
public static void AddUnitOfWork(this IServiceCollection services)
{
services.AddScoped(typeof(IUnitOfWork), typeof(UnitOfWork));
services.AddSingleton<UnitOfWorkInterceptor>();
}
}
}

View File

@@ -1,75 +0,0 @@
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Yi.Framework.Uow
{
public class UnitOfWork : IUnitOfWork
{
public bool IsTransactional { get; protected set; }
public IsolationLevel? IsolationLevel { get; protected set; }
/// <summary>
/// Milliseconds
/// </summary>
public int? Timeout { get; protected set; }
public void Init(bool isTransactional, IsolationLevel? isolationLevel, int? timeout)
{
IsTransactional = isTransactional;
IsolationLevel = isolationLevel;
Timeout = timeout;
}
public ISqlSugarClient SugarClient { get; set; }
/// <summary>
/// 因为sqlsugarclient的生命周期是作用域的也就是说一个请求线程内是共用一个client暂时先直接注入
/// </summary>
/// <param name="sqlSugarClient"></param>
public UnitOfWork(ISqlSugarClient sqlSugarClient)
{
this.SugarClient = sqlSugarClient;
}
public void Dispose()
{
SugarClient?.Dispose();
SugarClient?.Close();
}
public void BeginTran()
{
if (IsTransactional)
{
if (IsolationLevel.HasValue)
{
SugarClient.Ado.BeginTran(IsolationLevel.Value);
}
else
{
SugarClient.Ado.BeginTran();
}
}
}
public void CommitTran()
{
if (IsTransactional)
SugarClient.Ado.CommitTran();
}
public void RollbackTran()
{
if (IsTransactional)
SugarClient.Ado.RollbackTran();
}
}
}

View File

@@ -1,17 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Castle.Core" Version="5.1.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Yi.Framework.Repository\Yi.Framework.Repository.csproj" />
</ItemGroup>
</Project>