更改使用

This commit is contained in:
橙子
2023-01-07 19:41:48 +08:00
parent 898be6c733
commit aed0b8c2e5
7 changed files with 40 additions and 27 deletions

View File

@@ -48,10 +48,9 @@
//选择缓存 //选择缓存
"CacheSelect": "MemoryCache", "CacheSelect": "MemoryCache",
//RedisCacheAOP //缓存Aop
"RedisCacheAOP_Enabled": false, "CacheAOP_Enabled": false,
//MemoryCacheAOP
"MemoryCacheAOP_Enabled": false,
//缓存种子数据是否开启 //缓存种子数据是否开启
"CacheSeed_Enabled": false, "CacheSeed_Enabled": false,

View File

@@ -112,7 +112,7 @@ namespace Yi.Framework.Common.Base
public static string TryStringNull(this object value) public static string TryStringNull(this object value)
{ {
return value == null ? "" : value.ToString().Trim(); return value == null ? "" : value.ToString()!.Trim();
} }
/// <summary> /// <summary>

View File

@@ -10,7 +10,7 @@ using System.Threading.Tasks;
using Yi.Framework.Common.Base; using Yi.Framework.Common.Base;
using Yi.Framework.Common.Helper; using Yi.Framework.Common.Helper;
namespace Yi.Framework.WebCore.AOP namespace Yi.Framework.Core.Cache.Aop
{ {
public abstract class CacheAOPbase : IInterceptor public abstract class CacheAOPbase : IInterceptor
{ {

View File

@@ -1,10 +1,13 @@
using System; using Castle.DynamicProxy;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Yi.Framework.Common.Attribute;
using Yi.Framework.Core.Cache;
namespace Yi.Framework.WebCore.AOP namespace Yi.Framework.Core.Cache.Aop
{ {
public class MemoryCacheAOP : CacheAOPbase public class MemoryCacheAOP : CacheAOPbase
{ {
@@ -18,8 +21,8 @@ namespace Yi.Framework.WebCore.AOP
{ {
var method = invocation.MethodInvocationTarget ?? invocation.Method; var method = invocation.MethodInvocationTarget ?? invocation.Method;
var CachingAttribute = method.GetCustomAttributes(true).FirstOrDefault(x => x.GetType() == typeof(CachingAttribute)); var cachingAttribute = method.GetCustomAttributes(true).FirstOrDefault(x => x.GetType() == typeof(CachingAttribute));
if (CachingAttribute is CachingAttribute qCachingAttribute) if (cachingAttribute is CachingAttribute qCachingAttribute)
{ {
//获取自定义缓存键 //获取自定义缓存键
var cacheKey = CustomCacheKey(invocation); var cacheKey = CustomCacheKey(invocation);

View File

@@ -7,7 +7,7 @@ using System.Threading.Tasks;
using Yi.Framework.Core.Cache; using Yi.Framework.Core.Cache;
using Yi.Framework.Common.Attribute; using Yi.Framework.Common.Attribute;
namespace Yi.Framework.WebCore.AOP namespace Yi.Framework.Core.Cache.Aop
{ {
public class RedisCacheAOP : CacheAOPbase public class RedisCacheAOP : CacheAOPbase
{ {

View File

@@ -12,6 +12,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="AlibabaCloud.SDK.Dysmsapi20170525" Version="2.0.8" /> <PackageReference Include="AlibabaCloud.SDK.Dysmsapi20170525" Version="2.0.8" />
<PackageReference Include="Castle.Core" Version="5.1.1" />
<PackageReference Include="Consul" Version="1.6.10.3" /> <PackageReference Include="Consul" Version="1.6.10.3" />
<PackageReference Include="CSRedisCore" Version="3.6.9" /> <PackageReference Include="CSRedisCore" Version="3.6.9" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.1" /> <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.1" />

View File

@@ -12,11 +12,11 @@ using System.Linq;
using System.Reflection; using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using Yi.Framework.Common.Abstract; using Yi.Framework.Common.Abstract;
using Yi.Framework.Core.Cache.Aop;
using Yi.Framework.Interface; using Yi.Framework.Interface;
using Yi.Framework.Job; using Yi.Framework.Job;
using Yi.Framework.Repository; using Yi.Framework.Repository;
using Yi.Framework.Service; using Yi.Framework.Service;
using Yi.Framework.WebCore.AOP;
using Yi.Framework.WebCore.AutoFacExtend; using Yi.Framework.WebCore.AutoFacExtend;
using Yi.Framework.WebCore.CommonExtend; using Yi.Framework.WebCore.CommonExtend;
using Yi.Framework.WebCore.Impl; using Yi.Framework.WebCore.Impl;
@@ -46,25 +46,35 @@ namespace Yi.Framework.WebCore.AutoFacExtend
containerBuilder.RegisterType<HttpContextAccessor>().As<IHttpContextAccessor>().SingleInstance(); containerBuilder.RegisterType<HttpContextAccessor>().As<IHttpContextAccessor>().SingleInstance();
var cacheType = new List<Type>(); var cacheType = new List<Type>();
if (Appsettings.appBool("RedisCacheAOP_Enabled"))
{
containerBuilder.RegisterType<RedisCacheAOP>();
cacheType.Add(typeof(RedisCacheAOP));
}
if (Appsettings.appBool("MemoryCacheAOP_Enabled"))
{
containerBuilder.RegisterType<MemoryCacheAOP>();
cacheType.Add(typeof(MemoryCacheAOP));
}
//containerBuilder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>)).InstancePerLifetimeScope(); //containerBuilder.RegisterGeneric(typeof(Repository<>)).As(typeof(IRepository<>)).InstancePerLifetimeScope();
//containerBuilder.RegisterGeneric(typeof(BaseService<>)).As(typeof(IBaseService<>)).InstancePerLifetimeScope(); //containerBuilder.RegisterGeneric(typeof(BaseService<>)).As(typeof(IBaseService<>)).InstancePerLifetimeScope();
///反射注入服务层及接口层 ///反射注入服务层及接口层
var assemblysServices = GetDll("Yi.Framework.Service.dll"); var assemblysServices = GetDll("Yi.Framework.Service.dll");
containerBuilder.RegisterAssemblyTypes(assemblysServices).PropertiesAutowired(new AutowiredPropertySelector()) var regContainerBuilder = containerBuilder.RegisterAssemblyTypes(assemblysServices).PropertiesAutowired(new AutowiredPropertySelector())
.AsImplementedInterfaces() .AsImplementedInterfaces()
.InstancePerLifetimeScope() .InstancePerLifetimeScope()
.EnableInterfaceInterceptors() .EnableInterfaceInterceptors();
.InterceptedBy(cacheType.ToArray());
if (Appsettings.appBool("CacheAOP_Enabled"))
{
var cacheSelect = Appsettings.app("CacheSelect");
switch (cacheSelect)
{
case "Redis":
containerBuilder.RegisterType<RedisCacheAOP>();
cacheType.Add(typeof(RedisCacheAOP));
break;
case "MemoryCache":
containerBuilder.RegisterType<MemoryCacheAOP>();
cacheType.Add(typeof(MemoryCacheAOP));
break;
default: throw new ArgumentException("CacheSelect配置填的是什么东西俺不认得");
}
regContainerBuilder.InterceptedBy(cacheType.ToArray());
}
//开启工作单元拦截 //开启工作单元拦截
//.InterceptedBy(typeof(UnitOfWorkInterceptor)); //.InterceptedBy(typeof(UnitOfWorkInterceptor));