feat: 完成支持多db模式
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
using ArgumentException = System.ArgumentException;
|
||||||
|
|
||||||
namespace Yi.Framework.SqlSugarCore.Abstractions
|
namespace Yi.Framework.SqlSugarCore.Abstractions
|
||||||
{
|
{
|
||||||
@@ -53,6 +54,5 @@ namespace Yi.Framework.SqlSugarCore.Abstractions
|
|||||||
/// 开启Saas多租户
|
/// 开启Saas多租户
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool EnabledSaasMultiTenancy { get; set; } = false;
|
public bool EnabledSaasMultiTenancy { get; set; } = false;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,24 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Reflection;
|
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using SqlSugar;
|
|
||||||
|
|
||||||
namespace Yi.Framework.SqlSugarCore.Abstractions
|
|
||||||
{
|
|
||||||
public interface ISqlSugarDbConnectionCreator
|
|
||||||
{
|
|
||||||
DbConnOptions Options { get; }
|
|
||||||
Action<ISqlSugarClient> OnSqlSugarClientConfig { get; set; }
|
|
||||||
Action<object, DataAfterModel> DataExecuted { get; set; }
|
|
||||||
Action<object, DataFilterModel> DataExecuting { get; set; }
|
|
||||||
Action<string, SugarParameter[]> OnLogExecuting { get; set; }
|
|
||||||
Action<string, SugarParameter[]> OnLogExecuted { get; set; }
|
|
||||||
Action<PropertyInfo, EntityColumnInfo> EntityService { get; set; }
|
|
||||||
|
|
||||||
ConnectionConfig Build(Action<ConnectionConfig>? action = null);
|
|
||||||
void SetDbAop(ISqlSugarClient currentDb);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
|
|
||||||
namespace Yi.Framework.SqlSugarCore;
|
namespace Yi.Framework.SqlSugarCore.Abstractions;
|
||||||
|
|
||||||
public interface ISqlSugarDbContextDependencies
|
public interface ISqlSugarDbContextDependencies
|
||||||
{
|
{
|
||||||
@@ -9,20 +9,31 @@ using Yi.Framework.SqlSugarCore.Abstractions;
|
|||||||
|
|
||||||
namespace Yi.Framework.SqlSugarCore
|
namespace Yi.Framework.SqlSugarCore
|
||||||
{
|
{
|
||||||
public static class SqlsugarCoreExtensions
|
public static class SqlSugarCoreExtensions
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 新增db对象,可支持多个
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="service"></param>
|
||||||
|
/// <param name="serviceLifetime"></param>
|
||||||
|
/// <typeparam name="TDbContext"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
public static IServiceCollection AddYiDbContext<TDbContext>(this IServiceCollection service, ServiceLifetime serviceLifetime = ServiceLifetime.Transient) where TDbContext : class, ISqlSugarDbContextDependencies
|
public static IServiceCollection AddYiDbContext<TDbContext>(this IServiceCollection service, ServiceLifetime serviceLifetime = ServiceLifetime.Transient) where TDbContext : class, ISqlSugarDbContextDependencies
|
||||||
{
|
{
|
||||||
service.Add(new ServiceDescriptor(typeof(ISqlSugarDbContextDependencies), typeof(TDbContext), serviceLifetime));
|
service.AddTransient<ISqlSugarDbContextDependencies, TDbContext>();
|
||||||
return service;
|
return service;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 新增db对象,可支持多个
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="service"></param>
|
||||||
|
/// <param name="options"></param>
|
||||||
|
/// <typeparam name="TDbContext"></typeparam>
|
||||||
|
/// <returns></returns>
|
||||||
public static IServiceCollection AddYiDbContext<TDbContext>(this IServiceCollection service, Action<DbConnOptions> options) where TDbContext : class, ISqlSugarDbContextDependencies
|
public static IServiceCollection AddYiDbContext<TDbContext>(this IServiceCollection service, Action<DbConnOptions> options) where TDbContext : class, ISqlSugarDbContextDependencies
|
||||||
{
|
{
|
||||||
service.Configure<DbConnOptions>(ops =>
|
service.Configure<DbConnOptions>(options.Invoke);
|
||||||
{
|
|
||||||
options.Invoke(ops);
|
|
||||||
});
|
|
||||||
service.AddYiDbContext<TDbContext>();
|
service.AddYiDbContext<TDbContext>();
|
||||||
return service;
|
return service;
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using Volo.Abp.DependencyInjection;
|
using Volo.Abp.DependencyInjection;
|
||||||
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||||
|
|
||||||
namespace Yi.Framework.SqlSugarCore;
|
namespace Yi.Framework.SqlSugarCore;
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
using System.Reflection;
|
using System.Collections.Concurrent;
|
||||||
|
using System.Reflection;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using Volo.Abp.Data;
|
using Volo.Abp.Data;
|
||||||
using Volo.Abp.DependencyInjection;
|
using Volo.Abp.DependencyInjection;
|
||||||
using Volo.Abp.MultiTenancy;
|
using Volo.Abp.MultiTenancy;
|
||||||
|
using Volo.Abp.Threading;
|
||||||
using Volo.Abp.Users;
|
using Volo.Abp.Users;
|
||||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||||
using Check = Volo.Abp.Check;
|
using Check = Volo.Abp.Check;
|
||||||
@@ -17,6 +19,7 @@ namespace Yi.Framework.SqlSugarCore
|
|||||||
/// SqlSugar 客户端
|
/// SqlSugar 客户端
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ISqlSugarClient SqlSugarClient { get; private set; }
|
public ISqlSugarClient SqlSugarClient { get; private set; }
|
||||||
|
|
||||||
private IAbpLazyServiceProvider LazyServiceProvider { get; }
|
private IAbpLazyServiceProvider LazyServiceProvider { get; }
|
||||||
|
|
||||||
private ICurrentTenant CurrentTenant => LazyServiceProvider.LazyGetRequiredService<ICurrentTenant>();
|
private ICurrentTenant CurrentTenant => LazyServiceProvider.LazyGetRequiredService<ICurrentTenant>();
|
||||||
@@ -24,23 +27,29 @@ namespace Yi.Framework.SqlSugarCore
|
|||||||
|
|
||||||
private ISerializeService SerializeService => LazyServiceProvider.LazyGetRequiredService<ISerializeService>();
|
private ISerializeService SerializeService => LazyServiceProvider.LazyGetRequiredService<ISerializeService>();
|
||||||
|
|
||||||
private IEnumerable<ISqlSugarDbContextDependencies> SqlSugarDbContextDependencies=>LazyServiceProvider.LazyGetRequiredService<IEnumerable<ISqlSugarDbContextDependencies>>();
|
private IEnumerable<ISqlSugarDbContextDependencies> SqlSugarDbContextDependencies =>
|
||||||
|
LazyServiceProvider.LazyGetRequiredService<IEnumerable<ISqlSugarDbContextDependencies>>();
|
||||||
|
|
||||||
|
private static readonly ConcurrentDictionary<string, ConnectionConfig> ConnectionConfigCache = new();
|
||||||
|
|
||||||
public SqlSugarDbContextFactory(IAbpLazyServiceProvider lazyServiceProvider)
|
public SqlSugarDbContextFactory(IAbpLazyServiceProvider lazyServiceProvider)
|
||||||
{
|
{
|
||||||
LazyServiceProvider = lazyServiceProvider;
|
LazyServiceProvider = lazyServiceProvider;
|
||||||
|
|
||||||
|
var connectionString = GetCurrentConnectionString();
|
||||||
|
|
||||||
//获取连接配置操作,需要进行缓存
|
//获取连接配置操作,需要进行缓存
|
||||||
var connectionConfig = BuildConnectionConfig(action: options =>
|
var connectionConfig = ConnectionConfigCache.GetOrAdd(connectionString, (_) =>
|
||||||
{
|
BuildConnectionConfig(action: options =>
|
||||||
options.ConnectionString = GetCurrentConnectionString();
|
{
|
||||||
options.DbType = GetCurrentDbType();
|
options.ConnectionString = connectionString;
|
||||||
});
|
options.DbType = GetCurrentDbType();
|
||||||
|
}));
|
||||||
SqlSugarClient = new SqlSugarClient(connectionConfig);
|
SqlSugarClient = new SqlSugarClient(connectionConfig);
|
||||||
//生命周期,以下都可以直接使用sqlsugardb了
|
//生命周期,以下都可以直接使用sqlsugardb了
|
||||||
|
|
||||||
// Aop及多租户连接字符串和类型,需要单独设置
|
// Aop及多租户连接字符串和类型,需要单独设置
|
||||||
// Aop操作需要进行缓存
|
// Aop操作不能进行缓存
|
||||||
SetDbAop(SqlSugarClient);
|
SetDbAop(SqlSugarClient);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -52,33 +61,32 @@ namespace Yi.Framework.SqlSugarCore
|
|||||||
{
|
{
|
||||||
//替换默认序列化器
|
//替换默认序列化器
|
||||||
sqlSugarClient.CurrentConnectionConfig.ConfigureExternalServices.SerializeService = SerializeService;
|
sqlSugarClient.CurrentConnectionConfig.ConfigureExternalServices.SerializeService = SerializeService;
|
||||||
|
|
||||||
//将所有,ISqlSugarDbContextDependencies进行累加
|
//将所有,ISqlSugarDbContextDependencies进行累加
|
||||||
Action<string, SugarParameter[]> onLogExecuting=null;
|
Action<string, SugarParameter[]> onLogExecuting = null;
|
||||||
Action<string, SugarParameter[]> onLogExecuted=null;
|
Action<string, SugarParameter[]> onLogExecuted = null;
|
||||||
Action<object, DataFilterModel> dataExecuting = null;
|
Action<object, DataFilterModel> dataExecuting = null;
|
||||||
Action<object, DataAfterModel> dataExecuted = null;
|
Action<object, DataAfterModel> dataExecuted = null;
|
||||||
Action<ISqlSugarClient> onSqlSugarClientConfig = null;
|
Action<ISqlSugarClient> onSqlSugarClientConfig = null;
|
||||||
|
|
||||||
foreach (var dependency in SqlSugarDbContextDependencies.OrderBy(x=>x.ExecutionOrder))
|
foreach (var dependency in SqlSugarDbContextDependencies.OrderBy(x => x.ExecutionOrder))
|
||||||
{
|
{
|
||||||
onLogExecuting+= dependency.OnLogExecuting;
|
onLogExecuting += dependency.OnLogExecuting;
|
||||||
onLogExecuted += dependency.OnLogExecuted;
|
onLogExecuted += dependency.OnLogExecuted;
|
||||||
dataExecuting += dependency.DataExecuting;
|
dataExecuting += dependency.DataExecuting;
|
||||||
dataExecuted += dependency.DataExecuted;
|
dataExecuted += dependency.DataExecuted;
|
||||||
|
|
||||||
onSqlSugarClientConfig += dependency.OnSqlSugarClientConfig;
|
onSqlSugarClientConfig += dependency.OnSqlSugarClientConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
//最先存放db操作
|
//最先存放db操作
|
||||||
onSqlSugarClientConfig(sqlSugarClient);
|
onSqlSugarClientConfig(sqlSugarClient);
|
||||||
|
|
||||||
sqlSugarClient.Aop.OnLogExecuting = onLogExecuting;
|
|
||||||
sqlSugarClient.Aop.OnLogExecuted =onLogExecuted;
|
|
||||||
|
|
||||||
sqlSugarClient.Aop.DataExecuting = dataExecuting;
|
sqlSugarClient.Aop.OnLogExecuting =onLogExecuting;
|
||||||
sqlSugarClient.Aop.DataExecuted = dataExecuted;
|
sqlSugarClient.Aop.OnLogExecuted = onLogExecuted;
|
||||||
|
|
||||||
|
sqlSugarClient.Aop.DataExecuting =dataExecuting;
|
||||||
|
sqlSugarClient.Aop.DataExecuted =dataExecuted;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -86,14 +94,17 @@ namespace Yi.Framework.SqlSugarCore
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
/// <exception cref="ArgumentException"></exception>
|
/// <exception cref="ArgumentException"></exception>
|
||||||
protected virtual ConnectionConfig BuildConnectionConfig(Action<ConnectionConfig>? action=null)
|
protected virtual ConnectionConfig BuildConnectionConfig(Action<ConnectionConfig>? action = null)
|
||||||
{
|
{
|
||||||
var dbConnOptions = Options;
|
var dbConnOptions = Options;
|
||||||
|
|
||||||
#region 组装options
|
#region 组装options
|
||||||
|
|
||||||
if (dbConnOptions.DbType is null)
|
if (dbConnOptions.DbType is null)
|
||||||
{
|
{
|
||||||
throw new ArgumentException("DbType配置为空");
|
throw new ArgumentException("DbType配置为空");
|
||||||
}
|
}
|
||||||
|
|
||||||
var slavaConFig = new List<SlaveConnectionConfig>();
|
var slavaConFig = new List<SlaveConnectionConfig>();
|
||||||
if (dbConnOptions.EnabledReadWrite)
|
if (dbConnOptions.EnabledReadWrite)
|
||||||
{
|
{
|
||||||
@@ -110,12 +121,14 @@ namespace Yi.Framework.SqlSugarCore
|
|||||||
slavaConFig.Add(new SlaveConnectionConfig() { ConnectionString = s });
|
slavaConFig.Add(new SlaveConnectionConfig() { ConnectionString = s });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 组装连接config
|
#region 组装连接config
|
||||||
|
|
||||||
var connectionConfig = new ConnectionConfig()
|
var connectionConfig = new ConnectionConfig()
|
||||||
{
|
{
|
||||||
ConfigId= ConnectionStrings.DefaultConnectionStringName,
|
ConfigId = ConnectionStrings.DefaultConnectionStringName,
|
||||||
DbType = dbConnOptions.DbType ?? DbType.Sqlite,
|
DbType = dbConnOptions.DbType ?? DbType.Sqlite,
|
||||||
ConnectionString = dbConnOptions.Url,
|
ConnectionString = dbConnOptions.Url,
|
||||||
IsAutoCloseConnection = true,
|
IsAutoCloseConnection = true,
|
||||||
@@ -127,27 +140,28 @@ namespace Yi.Framework.SqlSugarCore
|
|||||||
EntityNameService = (type, entity) =>
|
EntityNameService = (type, entity) =>
|
||||||
{
|
{
|
||||||
if (dbConnOptions.EnableUnderLine && !entity.DbTableName.Contains('_'))
|
if (dbConnOptions.EnableUnderLine && !entity.DbTableName.Contains('_'))
|
||||||
entity.DbTableName = UtilMethods.ToUnderLine(entity.DbTableName);// 驼峰转下划线
|
entity.DbTableName = UtilMethods.ToUnderLine(entity.DbTableName); // 驼峰转下划线
|
||||||
},
|
},
|
||||||
EntityService = (c, p) =>
|
EntityService = (c, p) =>
|
||||||
{
|
{
|
||||||
if (new NullabilityInfoContext()
|
if (new NullabilityInfoContext()
|
||||||
.Create(c).WriteState is NullabilityState.Nullable)
|
.Create(c).WriteState is NullabilityState.Nullable)
|
||||||
{
|
{
|
||||||
p.IsNullable = true;
|
p.IsNullable = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dbConnOptions.EnableUnderLine && !p.IsIgnore && !p.DbColumnName.Contains('_'))
|
if (dbConnOptions.EnableUnderLine && !p.IsIgnore && !p.DbColumnName.Contains('_'))
|
||||||
p.DbColumnName = UtilMethods.ToUnderLine(p.DbColumnName);// 驼峰转下划线
|
p.DbColumnName = UtilMethods.ToUnderLine(p.DbColumnName); // 驼峰转下划线
|
||||||
|
|
||||||
//将所有,ISqlSugarDbContextDependencies的EntityService进行累加
|
//将所有,ISqlSugarDbContextDependencies的EntityService进行累加
|
||||||
//额外的实体服务需要这里配置,
|
//额外的实体服务需要这里配置,
|
||||||
|
|
||||||
Action<PropertyInfo, EntityColumnInfo> entityService = null;
|
Action<PropertyInfo, EntityColumnInfo> entityService = null;
|
||||||
foreach (var dependency in SqlSugarDbContextDependencies.OrderBy(x=>x.ExecutionOrder))
|
foreach (var dependency in SqlSugarDbContextDependencies.OrderBy(x => x.ExecutionOrder))
|
||||||
{
|
{
|
||||||
entityService += dependency.EntityService;
|
entityService += dependency.EntityService;
|
||||||
}
|
}
|
||||||
|
|
||||||
entityService(c, p);
|
entityService(c, p);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@@ -165,10 +179,12 @@ namespace Yi.Framework.SqlSugarCore
|
|||||||
{
|
{
|
||||||
action.Invoke(connectionConfig);
|
action.Invoke(connectionConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
return connectionConfig;
|
return connectionConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// db切换多库支持
|
/// db切换多库支持
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -177,7 +193,7 @@ namespace Yi.Framework.SqlSugarCore
|
|||||||
{
|
{
|
||||||
var connectionStringResolver = LazyServiceProvider.LazyGetRequiredService<IConnectionStringResolver>();
|
var connectionStringResolver = LazyServiceProvider.LazyGetRequiredService<IConnectionStringResolver>();
|
||||||
var connectionString =
|
var connectionString =
|
||||||
connectionStringResolver.ResolveAsync().ConfigureAwait(false).GetAwaiter().GetResult();
|
AsyncHelper.RunSync(() => connectionStringResolver.ResolveAsync());
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(connectionString))
|
if (string.IsNullOrWhiteSpace(connectionString))
|
||||||
{
|
{
|
||||||
@@ -230,7 +246,7 @@ namespace Yi.Framework.SqlSugarCore
|
|||||||
// 条件不满足时返回 null
|
// 条件不满足时返回 null
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public virtual void BackupDataBase()
|
public virtual void BackupDataBase()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,12 +6,9 @@ using Microsoft.Extensions.DependencyInjection.Extensions;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using SqlSugar;
|
using SqlSugar;
|
||||||
using Volo.Abp;
|
|
||||||
using Volo.Abp.Auditing;
|
|
||||||
using Volo.Abp.Data;
|
using Volo.Abp.Data;
|
||||||
using Volo.Abp.Domain;
|
using Volo.Abp.Domain;
|
||||||
using Volo.Abp.Domain.Repositories;
|
using Volo.Abp.Domain.Repositories;
|
||||||
using Volo.Abp.Modularity;
|
|
||||||
using Yi.Framework.SqlSugarCore.Abstractions;
|
using Yi.Framework.SqlSugarCore.Abstractions;
|
||||||
using Yi.Framework.SqlSugarCore.Repositories;
|
using Yi.Framework.SqlSugarCore.Repositories;
|
||||||
using Yi.Framework.SqlSugarCore.Uow;
|
using Yi.Framework.SqlSugarCore.Uow;
|
||||||
@@ -47,6 +44,7 @@ namespace Yi.Framework.SqlSugarCore
|
|||||||
//将默认db传递给abp连接字符串模块
|
//将默认db传递给abp连接字符串模块
|
||||||
Configure<AbpDbConnectionOptions>(x => { x.ConnectionStrings.Default = dbConfig.Url; });
|
Configure<AbpDbConnectionOptions>(x => { x.ConnectionStrings.Default = dbConfig.Url; });
|
||||||
|
|
||||||
|
context.Services.AddYiDbContext<DefaultSqlSugarDbContext>();
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,7 +70,6 @@ namespace Yi.Framework.SqlSugarCore
|
|||||||
|
|
||||||
|
|
||||||
logger.LogInformation(sb.ToString());
|
logger.LogInformation(sb.ToString());
|
||||||
//Todo:准备支持多租户种子数据及CodeFirst
|
|
||||||
|
|
||||||
if (options.EnabledCodeFirst)
|
if (options.EnabledCodeFirst)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -22,10 +22,7 @@ using Volo.Abp.AspNetCore.Serilog;
|
|||||||
using Volo.Abp.Auditing;
|
using Volo.Abp.Auditing;
|
||||||
using Volo.Abp.Autofac;
|
using Volo.Abp.Autofac;
|
||||||
using Volo.Abp.BackgroundJobs.Hangfire;
|
using Volo.Abp.BackgroundJobs.Hangfire;
|
||||||
using Volo.Abp.BackgroundWorkers;
|
|
||||||
using Volo.Abp.BackgroundWorkers.Hangfire;
|
|
||||||
using Volo.Abp.Caching;
|
using Volo.Abp.Caching;
|
||||||
using Volo.Abp.Hangfire;
|
|
||||||
using Volo.Abp.MultiTenancy;
|
using Volo.Abp.MultiTenancy;
|
||||||
using Volo.Abp.Swashbuckle;
|
using Volo.Abp.Swashbuckle;
|
||||||
using Yi.Abp.Application;
|
using Yi.Abp.Application;
|
||||||
@@ -74,7 +71,7 @@ namespace Yi.Abp.Web
|
|||||||
var configuration = context.Services.GetConfiguration();
|
var configuration = context.Services.GetConfiguration();
|
||||||
var host = context.Services.GetHostingEnvironment();
|
var host = context.Services.GetHostingEnvironment();
|
||||||
var service = context.Services;
|
var service = context.Services;
|
||||||
|
|
||||||
//请求日志
|
//请求日志
|
||||||
Configure<AbpAuditingOptions>(optios =>
|
Configure<AbpAuditingOptions>(optios =>
|
||||||
{
|
{
|
||||||
@@ -87,236 +84,236 @@ namespace Yi.Abp.Web
|
|||||||
options.IgnoredUrls.Add("/api/app/file/");
|
options.IgnoredUrls.Add("/api/app/file/");
|
||||||
options.IgnoredUrls.Add("/hangfire");
|
options.IgnoredUrls.Add("/hangfire");
|
||||||
});
|
});
|
||||||
|
|
||||||
//采用furion格式的规范化api,默认不开启,使用abp优雅的方式
|
//采用furion格式的规范化api,默认不开启,使用abp优雅的方式
|
||||||
//你没看错。。。
|
//你没看错。。。
|
||||||
//service.AddFurionUnifyResultApi();
|
//service.AddFurionUnifyResultApi();
|
||||||
|
|
||||||
//配置错误处理显示详情
|
//配置错误处理显示详情
|
||||||
Configure<AbpExceptionHandlingOptions>(options => { options.SendExceptionsDetailsToClients = true; });
|
Configure<AbpExceptionHandlingOptions>(options => { options.SendExceptionsDetailsToClients = true; });
|
||||||
|
|
||||||
//动态Api
|
//动态Api
|
||||||
Configure<AbpAspNetCoreMvcOptions>(options =>
|
Configure<AbpAspNetCoreMvcOptions>(options =>
|
||||||
|
{
|
||||||
|
options.ConventionalControllers.Create(typeof(YiAbpApplicationModule).Assembly,
|
||||||
|
options => options.RemoteServiceName = "default");
|
||||||
|
options.ConventionalControllers.Create(typeof(YiFrameworkRbacApplicationModule).Assembly,
|
||||||
|
options => options.RemoteServiceName = "rbac");
|
||||||
|
options.ConventionalControllers.Create(typeof(YiFrameworkBbsApplicationModule).Assembly,
|
||||||
|
options => options.RemoteServiceName = "bbs");
|
||||||
|
options.ConventionalControllers.Create(typeof(YiFrameworkChatHubApplicationModule).Assembly,
|
||||||
|
options => options.RemoteServiceName = "chat-hub");
|
||||||
|
options.ConventionalControllers.Create(
|
||||||
|
typeof(YiFrameworkTenantManagementApplicationModule).Assembly,
|
||||||
|
options => options.RemoteServiceName = "tenant-management");
|
||||||
|
options.ConventionalControllers.Create(typeof(YiFrameworkCodeGenApplicationModule).Assembly,
|
||||||
|
options => options.RemoteServiceName = "code-gen");
|
||||||
|
|
||||||
|
//统一前缀
|
||||||
|
options.ConventionalControllers.ConventionalControllerSettings.ForEach(x => x.RootPath = "api/app");
|
||||||
|
});
|
||||||
|
|
||||||
|
//【NewtonsoftJson严重问题!!!!!逆天】设置api格式,留给后人铭记
|
||||||
|
// service.AddControllers().AddNewtonsoftJson(options =>
|
||||||
|
// {
|
||||||
|
// options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
||||||
|
// options.SerializerSettings.Converters.Add(new StringEnumConverter());
|
||||||
|
// });
|
||||||
|
|
||||||
|
//请使用微软的,注意abp date又包了一层,采用DefaultJsonTypeInfoResolver统一覆盖
|
||||||
|
Configure<JsonOptions>(options =>
|
||||||
|
{
|
||||||
|
options.JsonSerializerOptions.TypeInfoResolver = new DefaultJsonTypeInfoResolver();
|
||||||
|
options.JsonSerializerOptions.Converters.Add(new DatetimeJsonConverter());
|
||||||
|
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
|
||||||
|
});
|
||||||
|
|
||||||
|
//设置缓存不要过期,默认滑动20分钟
|
||||||
|
Configure<AbpDistributedCacheOptions>(cacheOptions =>
|
||||||
|
{
|
||||||
|
cacheOptions.GlobalCacheEntryOptions.SlidingExpiration = null;
|
||||||
|
//缓存key前缀
|
||||||
|
cacheOptions.KeyPrefix = "Yi:";
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
Configure<AbpAntiForgeryOptions>(options => { options.AutoValidate = false; });
|
||||||
|
|
||||||
|
//Swagger
|
||||||
|
context.Services.AddYiSwaggerGen<YiAbpWebModule>(options =>
|
||||||
|
{
|
||||||
|
options.SwaggerDoc("default",
|
||||||
|
new OpenApiInfo { Title = "Yi.Framework.Abp", Version = "v1", Description = "集大成者" });
|
||||||
|
});
|
||||||
|
|
||||||
|
//跨域
|
||||||
|
context.Services.AddCors(options =>
|
||||||
|
{
|
||||||
|
options.AddPolicy(DefaultCorsPolicyName, builder =>
|
||||||
{
|
{
|
||||||
options.ConventionalControllers.Create(typeof(YiAbpApplicationModule).Assembly,
|
builder
|
||||||
options => options.RemoteServiceName = "default");
|
.WithOrigins(
|
||||||
options.ConventionalControllers.Create(typeof(YiFrameworkRbacApplicationModule).Assembly,
|
configuration["App:CorsOrigins"]!
|
||||||
options => options.RemoteServiceName = "rbac");
|
.Split(";", StringSplitOptions.RemoveEmptyEntries)
|
||||||
options.ConventionalControllers.Create(typeof(YiFrameworkBbsApplicationModule).Assembly,
|
.Select(o => o.RemovePostFix("/"))
|
||||||
options => options.RemoteServiceName = "bbs");
|
.ToArray()
|
||||||
options.ConventionalControllers.Create(typeof(YiFrameworkChatHubApplicationModule).Assembly,
|
)
|
||||||
options => options.RemoteServiceName = "chat-hub");
|
.WithAbpExposedHeaders()
|
||||||
options.ConventionalControllers.Create(
|
.SetIsOriginAllowedToAllowWildcardSubdomains()
|
||||||
typeof(YiFrameworkTenantManagementApplicationModule).Assembly,
|
.AllowAnyHeader()
|
||||||
options => options.RemoteServiceName = "tenant-management");
|
.AllowAnyMethod()
|
||||||
options.ConventionalControllers.Create(typeof(YiFrameworkCodeGenApplicationModule).Assembly,
|
.AllowCredentials();
|
||||||
options => options.RemoteServiceName = "code-gen");
|
|
||||||
|
|
||||||
//统一前缀
|
|
||||||
options.ConventionalControllers.ConventionalControllerSettings.ForEach(x => x.RootPath = "api/app");
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
//【NewtonsoftJson严重问题!!!!!逆天】设置api格式,留给后人铭记
|
//配置多租户
|
||||||
// service.AddControllers().AddNewtonsoftJson(options =>
|
Configure<AbpTenantResolveOptions>(options =>
|
||||||
// {
|
{
|
||||||
// options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
|
//基于cookie jwt不好用,有坑
|
||||||
// options.SerializerSettings.Converters.Add(new StringEnumConverter());
|
options.TenantResolvers.Clear();
|
||||||
// });
|
options.TenantResolvers.Add(new HeaderTenantResolveContributor());
|
||||||
|
//options.TenantResolvers.Add(new HeaderTenantResolveContributor());
|
||||||
|
//options.TenantResolvers.Add(new CookieTenantResolveContributor());
|
||||||
|
//options.TenantResolvers.RemoveAll(x => x.Name == CookieTenantResolveContributor.ContributorName);
|
||||||
|
});
|
||||||
|
|
||||||
//请使用微软的,注意abp date又包了一层,采用DefaultJsonTypeInfoResolver统一覆盖
|
//配置Hangfire定时任务存储,开启redis后,优先使用redis
|
||||||
Configure<JsonOptions>(options =>
|
var redisConfiguration = configuration["Redis:Configuration"];
|
||||||
|
var redisEnabled = configuration["Redis:IsEnabled"];
|
||||||
|
context.Services.AddHangfire(config =>
|
||||||
|
{
|
||||||
|
if (redisEnabled.IsNullOrEmpty() || bool.Parse(redisEnabled))
|
||||||
{
|
{
|
||||||
options.JsonSerializerOptions.TypeInfoResolver = new DefaultJsonTypeInfoResolver();
|
config.UseRedisStorage(
|
||||||
options.JsonSerializerOptions.Converters.Add(new DatetimeJsonConverter());
|
ConnectionMultiplexer.Connect(redisConfiguration),
|
||||||
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
|
new RedisStorageOptions()
|
||||||
});
|
|
||||||
|
|
||||||
//设置缓存不要过期,默认滑动20分钟
|
|
||||||
Configure<AbpDistributedCacheOptions>(cacheOptions =>
|
|
||||||
{
|
|
||||||
cacheOptions.GlobalCacheEntryOptions.SlidingExpiration = null;
|
|
||||||
//缓存key前缀
|
|
||||||
cacheOptions.KeyPrefix = "Yi:";
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
Configure<AbpAntiForgeryOptions>(options => { options.AutoValidate = false; });
|
|
||||||
|
|
||||||
//Swagger
|
|
||||||
context.Services.AddYiSwaggerGen<YiAbpWebModule>(options =>
|
|
||||||
{
|
|
||||||
options.SwaggerDoc("default",
|
|
||||||
new OpenApiInfo { Title = "Yi.Framework.Abp", Version = "v1", Description = "集大成者" });
|
|
||||||
});
|
|
||||||
|
|
||||||
//跨域
|
|
||||||
context.Services.AddCors(options =>
|
|
||||||
{
|
|
||||||
options.AddPolicy(DefaultCorsPolicyName, builder =>
|
|
||||||
{
|
|
||||||
builder
|
|
||||||
.WithOrigins(
|
|
||||||
configuration["App:CorsOrigins"]!
|
|
||||||
.Split(";", StringSplitOptions.RemoveEmptyEntries)
|
|
||||||
.Select(o => o.RemovePostFix("/"))
|
|
||||||
.ToArray()
|
|
||||||
)
|
|
||||||
.WithAbpExposedHeaders()
|
|
||||||
.SetIsOriginAllowedToAllowWildcardSubdomains()
|
|
||||||
.AllowAnyHeader()
|
|
||||||
.AllowAnyMethod()
|
|
||||||
.AllowCredentials();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
//配置多租户
|
|
||||||
Configure<AbpTenantResolveOptions>(options =>
|
|
||||||
{
|
|
||||||
//基于cookie jwt不好用,有坑
|
|
||||||
options.TenantResolvers.Clear();
|
|
||||||
options.TenantResolvers.Add(new HeaderTenantResolveContributor());
|
|
||||||
//options.TenantResolvers.Add(new HeaderTenantResolveContributor());
|
|
||||||
//options.TenantResolvers.Add(new CookieTenantResolveContributor());
|
|
||||||
//options.TenantResolvers.RemoveAll(x => x.Name == CookieTenantResolveContributor.ContributorName);
|
|
||||||
});
|
|
||||||
|
|
||||||
//配置Hangfire定时任务存储,开启redis后,优先使用redis
|
|
||||||
var redisConfiguration = configuration["Redis:Configuration"];
|
|
||||||
var redisEnabled = configuration["Redis:IsEnabled"];
|
|
||||||
context.Services.AddHangfire(config =>
|
|
||||||
{
|
|
||||||
if (redisEnabled.IsNullOrEmpty() || bool.Parse(redisEnabled))
|
|
||||||
{
|
|
||||||
config.UseRedisStorage(
|
|
||||||
ConnectionMultiplexer.Connect(redisConfiguration),
|
|
||||||
new RedisStorageOptions()
|
|
||||||
{
|
|
||||||
InvisibilityTimeout = TimeSpan.FromHours(1), //JOB允许执行1小时
|
|
||||||
Prefix = "Yi:HangfireJob:"
|
|
||||||
}).WithJobExpirationTimeout(TimeSpan.FromHours(1));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
config.UseMemoryStorage();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
//速率限制
|
|
||||||
//每60秒限制100个请求,滑块添加,分6段
|
|
||||||
service.AddRateLimiter(_ =>
|
|
||||||
{
|
|
||||||
_.RejectionStatusCode = StatusCodes.Status429TooManyRequests;
|
|
||||||
_.OnRejected = (context, _) =>
|
|
||||||
{
|
|
||||||
if (context.Lease.TryGetMetadata(MetadataName.RetryAfter, out var retryAfter))
|
|
||||||
{
|
{
|
||||||
context.HttpContext.Response.Headers.RetryAfter =
|
InvisibilityTimeout = TimeSpan.FromHours(1), //JOB允许执行1小时
|
||||||
((int)retryAfter.TotalSeconds).ToString(NumberFormatInfo.InvariantInfo);
|
Prefix = "Yi:HangfireJob:"
|
||||||
}
|
}).WithJobExpirationTimeout(TimeSpan.FromHours(1));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
config.UseMemoryStorage();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
context.HttpContext.Response.StatusCode = StatusCodes.Status429TooManyRequests;
|
//速率限制
|
||||||
context.HttpContext.Response.WriteAsync("Too many requests. Please try again later.");
|
//每60秒限制100个请求,滑块添加,分6段
|
||||||
|
service.AddRateLimiter(_ =>
|
||||||
|
{
|
||||||
|
_.RejectionStatusCode = StatusCodes.Status429TooManyRequests;
|
||||||
|
_.OnRejected = (context, _) =>
|
||||||
|
{
|
||||||
|
if (context.Lease.TryGetMetadata(MetadataName.RetryAfter, out var retryAfter))
|
||||||
|
{
|
||||||
|
context.HttpContext.Response.Headers.RetryAfter =
|
||||||
|
((int)retryAfter.TotalSeconds).ToString(NumberFormatInfo.InvariantInfo);
|
||||||
|
}
|
||||||
|
|
||||||
return new ValueTask();
|
context.HttpContext.Response.StatusCode = StatusCodes.Status429TooManyRequests;
|
||||||
|
context.HttpContext.Response.WriteAsync("Too many requests. Please try again later.");
|
||||||
|
|
||||||
|
return new ValueTask();
|
||||||
|
};
|
||||||
|
|
||||||
|
//全局使用,链式表达式
|
||||||
|
_.GlobalLimiter = PartitionedRateLimiter.CreateChained(
|
||||||
|
PartitionedRateLimiter.Create<HttpContext, string>(httpContext =>
|
||||||
|
{
|
||||||
|
var userAgent = httpContext.Request.Headers.UserAgent.ToString();
|
||||||
|
|
||||||
|
return RateLimitPartition.GetSlidingWindowLimiter
|
||||||
|
(userAgent, _ =>
|
||||||
|
new SlidingWindowRateLimiterOptions
|
||||||
|
{
|
||||||
|
PermitLimit = 1000,
|
||||||
|
Window = TimeSpan.FromSeconds(60),
|
||||||
|
SegmentsPerWindow = 6,
|
||||||
|
QueueProcessingOrder = QueueProcessingOrder.OldestFirst
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
//jwt鉴权
|
||||||
|
var jwtOptions = configuration.GetSection(nameof(JwtOptions)).Get<JwtOptions>();
|
||||||
|
var refreshJwtOptions = configuration.GetSection(nameof(RefreshJwtOptions)).Get<RefreshJwtOptions>();
|
||||||
|
|
||||||
|
context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
||||||
|
.AddJwtBearer(options =>
|
||||||
|
{
|
||||||
|
options.TokenValidationParameters = new TokenValidationParameters
|
||||||
|
{
|
||||||
|
ClockSkew = TimeSpan.Zero,
|
||||||
|
ValidateIssuerSigningKey = true,
|
||||||
|
ValidIssuer = jwtOptions.Issuer,
|
||||||
|
ValidAudience = jwtOptions.Audience,
|
||||||
|
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtOptions.SecurityKey))
|
||||||
};
|
};
|
||||||
|
options.Events = new JwtBearerEvents
|
||||||
//全局使用,链式表达式
|
|
||||||
_.GlobalLimiter = PartitionedRateLimiter.CreateChained(
|
|
||||||
PartitionedRateLimiter.Create<HttpContext, string>(httpContext =>
|
|
||||||
{
|
|
||||||
var userAgent = httpContext.Request.Headers.UserAgent.ToString();
|
|
||||||
|
|
||||||
return RateLimitPartition.GetSlidingWindowLimiter
|
|
||||||
(userAgent, _ =>
|
|
||||||
new SlidingWindowRateLimiterOptions
|
|
||||||
{
|
|
||||||
PermitLimit = 1000,
|
|
||||||
Window = TimeSpan.FromSeconds(60),
|
|
||||||
SegmentsPerWindow = 6,
|
|
||||||
QueueProcessingOrder = QueueProcessingOrder.OldestFirst
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
//jwt鉴权
|
|
||||||
var jwtOptions = configuration.GetSection(nameof(JwtOptions)).Get<JwtOptions>();
|
|
||||||
var refreshJwtOptions = configuration.GetSection(nameof(RefreshJwtOptions)).Get<RefreshJwtOptions>();
|
|
||||||
|
|
||||||
context.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
|
|
||||||
.AddJwtBearer(options =>
|
|
||||||
{
|
{
|
||||||
options.TokenValidationParameters = new TokenValidationParameters
|
OnMessageReceived = context =>
|
||||||
{
|
{
|
||||||
ClockSkew = TimeSpan.Zero,
|
//优先Query中获取,再去cookies中获取
|
||||||
ValidateIssuerSigningKey = true,
|
var accessToken = context.Request.Query["access_token"];
|
||||||
ValidIssuer = jwtOptions.Issuer,
|
if (!string.IsNullOrEmpty(accessToken))
|
||||||
ValidAudience = jwtOptions.Audience,
|
|
||||||
IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(jwtOptions.SecurityKey))
|
|
||||||
};
|
|
||||||
options.Events = new JwtBearerEvents
|
|
||||||
{
|
|
||||||
OnMessageReceived = context =>
|
|
||||||
{
|
{
|
||||||
//优先Query中获取,再去cookies中获取
|
context.Token = accessToken;
|
||||||
var accessToken = context.Request.Query["access_token"];
|
}
|
||||||
if (!string.IsNullOrEmpty(accessToken))
|
else
|
||||||
|
{
|
||||||
|
if (context.Request.Cookies.TryGetValue("Token", out var cookiesToken))
|
||||||
{
|
{
|
||||||
context.Token = accessToken;
|
context.Token = cookiesToken;
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (context.Request.Cookies.TryGetValue("Token",out var cookiesToken))
|
|
||||||
{
|
|
||||||
context.Token = cookiesToken;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.AddJwtBearer(TokenTypeConst.Refresh, options =>
|
||||||
|
{
|
||||||
|
options.TokenValidationParameters = new TokenValidationParameters
|
||||||
|
{
|
||||||
|
ClockSkew = TimeSpan.Zero,
|
||||||
|
ValidateIssuerSigningKey = true,
|
||||||
|
ValidIssuer = refreshJwtOptions.Issuer,
|
||||||
|
ValidAudience = refreshJwtOptions.Audience,
|
||||||
|
IssuerSigningKey =
|
||||||
|
new SymmetricSecurityKey(Encoding.UTF8.GetBytes(refreshJwtOptions.SecurityKey))
|
||||||
|
};
|
||||||
|
options.Events = new JwtBearerEvents
|
||||||
|
{
|
||||||
|
OnMessageReceived = context =>
|
||||||
|
{
|
||||||
|
var refresh_token = context.Request.Headers["refresh_token"];
|
||||||
|
if (!string.IsNullOrEmpty(refresh_token))
|
||||||
|
{
|
||||||
|
context.Token = refresh_token;
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
};
|
|
||||||
})
|
var refreshToken = context.Request.Query["refresh_token"];
|
||||||
.AddJwtBearer(TokenTypeConst.Refresh, options =>
|
if (!string.IsNullOrEmpty(refreshToken))
|
||||||
{
|
|
||||||
options.TokenValidationParameters = new TokenValidationParameters
|
|
||||||
{
|
|
||||||
ClockSkew = TimeSpan.Zero,
|
|
||||||
ValidateIssuerSigningKey = true,
|
|
||||||
ValidIssuer = refreshJwtOptions.Issuer,
|
|
||||||
ValidAudience = refreshJwtOptions.Audience,
|
|
||||||
IssuerSigningKey =
|
|
||||||
new SymmetricSecurityKey(Encoding.UTF8.GetBytes(refreshJwtOptions.SecurityKey))
|
|
||||||
};
|
|
||||||
options.Events = new JwtBearerEvents
|
|
||||||
{
|
|
||||||
OnMessageReceived = context =>
|
|
||||||
{
|
{
|
||||||
var refresh_token = context.Request.Headers["refresh_token"];
|
context.Token = refreshToken;
|
||||||
if (!string.IsNullOrEmpty(refresh_token))
|
|
||||||
{
|
|
||||||
context.Token = refresh_token;
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
|
||||||
var refreshToken = context.Request.Query["refresh_token"];
|
|
||||||
if (!string.IsNullOrEmpty(refreshToken))
|
|
||||||
{
|
|
||||||
context.Token = refreshToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
})
|
|
||||||
.AddQQ(options => { configuration.GetSection("OAuth:QQ").Bind(options); })
|
|
||||||
.AddGitee(options => { configuration.GetSection("OAuth:Gitee").Bind(options); });
|
|
||||||
|
|
||||||
//授权
|
return Task.CompletedTask;
|
||||||
context.Services.AddAuthorization();
|
}
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.AddQQ(options => { configuration.GetSection("OAuth:QQ").Bind(options); })
|
||||||
|
.AddGitee(options => { configuration.GetSection("OAuth:Gitee").Bind(options); });
|
||||||
|
|
||||||
|
//授权
|
||||||
|
context.Services.AddAuthorization();
|
||||||
return Task.CompletedTask;
|
|
||||||
}
|
|
||||||
|
return Task.CompletedTask;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
|
public override async Task OnApplicationInitializationAsync(ApplicationInitializationContext context)
|
||||||
@@ -373,12 +370,13 @@ namespace Yi.Abp.Web
|
|||||||
|
|
||||||
//日志记录
|
//日志记录
|
||||||
app.UseAbpSerilogEnrichers();
|
app.UseAbpSerilogEnrichers();
|
||||||
|
|
||||||
//Hangfire定时任务面板,可配置授权,意框架支持jwt
|
//Hangfire定时任务面板,可配置授权,意框架支持jwt
|
||||||
app.UseAbpHangfireDashboard("/hangfire", options =>
|
app.UseAbpHangfireDashboard("/hangfire",
|
||||||
{
|
options =>
|
||||||
options.AsyncAuthorization = new[] { new YiTokenAuthorizationFilter(app.ApplicationServices) };
|
{
|
||||||
});
|
options.AsyncAuthorization = new[] { new YiTokenAuthorizationFilter(app.ApplicationServices) };
|
||||||
|
});
|
||||||
|
|
||||||
//终节点
|
//终节点
|
||||||
app.UseConfiguredEndpoints();
|
app.UseConfiguredEndpoints();
|
||||||
|
|||||||
Reference in New Issue
Block a user