Merge branch 'refs/heads/abp' into digital-collectibles
# Conflicts: # Yi.Abp.Net8/src/Yi.Abp.Web/YiAbpWebModule.cs
This commit is contained in:
@@ -9,18 +9,20 @@ using Microsoft.OpenApi.Any;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||
using Volo.Abp.AspNetCore.Mvc;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
using Volo.Abp.Options;
|
||||
|
||||
namespace Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
public static class SwaggerAddExtensions
|
||||
{
|
||||
public static IServiceCollection AddYiSwaggerGen<Program>(this IServiceCollection services, Action<SwaggerGenOptions>? action=null)
|
||||
public static IServiceCollection AddYiSwaggerGen<Program>(this IServiceCollection services,
|
||||
Action<SwaggerGenOptions>? action = null)
|
||||
{
|
||||
var mvcOptions = services.GetPreConfigureActions<AbpAspNetCoreMvcOptions>().Configure();
|
||||
|
||||
var serviceProvider = services.BuildServiceProvider();
|
||||
var mvcOptions = serviceProvider.GetRequiredService<IOptions<AbpAspNetCoreMvcOptions>>();
|
||||
|
||||
var mvcSettings = mvcOptions.Value.ConventionalControllers.ConventionalControllerSettings.DistinctBy(x => x.RemoteServiceName);
|
||||
var mvcSettings =
|
||||
mvcOptions.ConventionalControllers.ConventionalControllerSettings.DistinctBy(x => x.RemoteServiceName);
|
||||
|
||||
|
||||
services.AddAbpSwaggerGen(
|
||||
@@ -36,7 +38,8 @@ namespace Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
if (!options.SwaggerGeneratorOptions.SwaggerDocs.ContainsKey(setting.RemoteServiceName))
|
||||
{
|
||||
options.SwaggerDoc(setting.RemoteServiceName, new OpenApiInfo { Title = setting.RemoteServiceName, Version = "v1" });
|
||||
options.SwaggerDoc(setting.RemoteServiceName,
|
||||
new OpenApiInfo { Title = setting.RemoteServiceName, Version = "v1" });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,12 +48,15 @@ namespace Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection
|
||||
{
|
||||
if (apiDesc.ActionDescriptor is ControllerActionDescriptor controllerActionDescriptor)
|
||||
{
|
||||
var settingOrNull = mvcSettings.Where(x => x.Assembly == controllerActionDescriptor.ControllerTypeInfo.Assembly).FirstOrDefault();
|
||||
var settingOrNull = mvcSettings
|
||||
.Where(x => x.Assembly == controllerActionDescriptor.ControllerTypeInfo.Assembly)
|
||||
.FirstOrDefault();
|
||||
if (settingOrNull is not null)
|
||||
{
|
||||
return docName == settingOrNull.RemoteServiceName;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
@@ -87,7 +93,6 @@ namespace Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection
|
||||
);
|
||||
|
||||
|
||||
|
||||
return services;
|
||||
}
|
||||
}
|
||||
@@ -103,7 +108,6 @@ namespace Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection
|
||||
/// </summary>
|
||||
/// <param name="model"></param>
|
||||
/// <param name="context"></param>
|
||||
|
||||
public void Apply(OpenApiSchema model, SchemaFilterContext context)
|
||||
{
|
||||
if (context.Type.IsEnum)
|
||||
@@ -121,9 +125,10 @@ namespace Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection
|
||||
Enum e = (Enum)Enum.Parse(context.Type, name);
|
||||
var descrptionOrNull = GetEnumDescription(e);
|
||||
model.Enum.Add(new OpenApiString(name));
|
||||
stringBuilder.Append($"【枚举:{name}{(descrptionOrNull is null ? string.Empty : $"({descrptionOrNull})")}={Convert.ToInt64(Enum.Parse(context.Type, name))}】<br />");
|
||||
stringBuilder.Append(
|
||||
$"【枚举:{name}{(descrptionOrNull is null ? string.Empty : $"({descrptionOrNull})")}={Convert.ToInt64(Enum.Parse(context.Type, name))}】<br />");
|
||||
});
|
||||
model.Description= stringBuilder.ToString();
|
||||
model.Description = stringBuilder.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,13 +138,13 @@ namespace Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection
|
||||
var attributes = (DescriptionAttribute[])fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false);
|
||||
return attributes.Length > 0 ? attributes[0].Description : null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public class AddRequiredHeaderParameter : IOperationFilter
|
||||
{
|
||||
public static string HeaderKey { get; set; } = "__tenant";
|
||||
|
||||
public void Apply(OpenApiOperation operation, OperationFilterContext context)
|
||||
{
|
||||
if (operation.Parameters == null)
|
||||
@@ -150,7 +155,7 @@ namespace Yi.Framework.AspNetCore.Microsoft.Extensions.DependencyInjection
|
||||
In = ParameterLocation.Header,
|
||||
Required = false,
|
||||
AllowEmptyValue = true,
|
||||
Description="租户id或者租户名称(可空为默认租户)"
|
||||
Description = "租户id或者租户名称(可空为默认租户)"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ namespace Yi.Framework.SqlSugarCore.Uow
|
||||
Logger = NullLogger<UnitOfWorkSqlsugarDbContextProvider<TDbContext>>.Instance;
|
||||
}
|
||||
|
||||
//private static object _databaseApiLock = new object();
|
||||
public virtual async Task<TDbContext> GetDbContextAsync()
|
||||
{
|
||||
|
||||
@@ -48,19 +47,16 @@ namespace Yi.Framework.SqlSugarCore.Uow
|
||||
|
||||
|
||||
var unitOfWork = UnitOfWorkManager.Current;
|
||||
if (unitOfWork == null /*|| unitOfWork.Options.IsTransactional == false*/)
|
||||
if (unitOfWork == null )
|
||||
{
|
||||
var dbContext = (TDbContext)ServiceProvider.GetRequiredService<ISqlSugarDbContext>();
|
||||
//提高体验,取消工作单元强制性
|
||||
//throw new AbpException("A DbContext can only be created inside a unit of work!");
|
||||
//var dbContext = (TDbContext)ServiceProvider.GetRequiredService<ISqlSugarDbContext>();
|
||||
//如果不启用工作单元,创建一个新的db,不开启事务即可
|
||||
return dbContext;
|
||||
//return dbContext;
|
||||
|
||||
//2024-11-30,改回强制性使用工作单元,否则容易造成歧义
|
||||
throw new AbpException("DbContext 只能在工作单元内工作,当前DbContext没有工作单元,如需创建新线程并发操作,请手动创建工作单元");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//尝试当前工作单元获取db
|
||||
var databaseApi = unitOfWork.FindDatabaseApi(dbContextKey);
|
||||
|
||||
|
||||
@@ -423,13 +423,13 @@ namespace Yi.Framework.Rbac.Application.Services
|
||||
{
|
||||
//将后端菜单转换成前端路由,组件级别需要过滤
|
||||
output =
|
||||
ObjectMapper.Map<List<MenuDto>, List<MenuAggregateRoot>>(menus).Vue3RuoYiRouterBuild();
|
||||
ObjectMapper.Map<List<MenuDto>, List<MenuAggregateRoot>>(menus.Where(x=>x.MenuSource==MenuSourceEnum.Ruoyi).ToList()).Vue3RuoYiRouterBuild();
|
||||
}
|
||||
else if (routerType == "pure")
|
||||
{
|
||||
//将后端菜单转换成前端路由,组件级别需要过滤
|
||||
output =
|
||||
ObjectMapper.Map<List<MenuDto>, List<MenuAggregateRoot>>(menus).Vue3PureRouterBuild();
|
||||
ObjectMapper.Map<List<MenuDto>, List<MenuAggregateRoot>>(menus.Where(x=>x.MenuSource==MenuSourceEnum.Pure).ToList()).Vue3PureRouterBuild();
|
||||
}
|
||||
|
||||
return output;
|
||||
|
||||
@@ -9,8 +9,8 @@ namespace Yi.Framework.Rbac.Domain.Shared.Dtos
|
||||
public HashSet<RoleDto> Roles { get; set; } = new();
|
||||
public HashSet<MenuDto> Menus { get; set; } = new();
|
||||
|
||||
public List<string> RoleCodes { get; set; } = new();
|
||||
public List<string> PermissionCodes { get; set; } = new();
|
||||
public HashSet<string> RoleCodes { get; set; } = new();
|
||||
public HashSet<string> PermissionCodes { get; set; } = new();
|
||||
}
|
||||
|
||||
public class UserDto
|
||||
|
||||
@@ -217,8 +217,8 @@ namespace Yi.Framework.Rbac.Domain.Managers
|
||||
}
|
||||
else
|
||||
{
|
||||
dto.PermissionCodes?.ForEach(per => AddToClaim(claims, TokenTypeConst.Permission, per));
|
||||
dto.RoleCodes?.ForEach(role => AddToClaim(claims, AbpClaimTypes.Role, role));
|
||||
dto.PermissionCodes?.ToList()?.ForEach(per => AddToClaim(claims, TokenTypeConst.Permission, per));
|
||||
dto.RoleCodes?.ToList()?.ForEach(role => AddToClaim(claims, AbpClaimTypes.Role, role));
|
||||
}
|
||||
|
||||
return claims;
|
||||
|
||||
@@ -67,7 +67,8 @@ namespace Yi.Abp.Application.Services
|
||||
public async Task GetUowAsync()
|
||||
{
|
||||
//魔改
|
||||
// 用户体验优先,万金油模式,支持高并发。支持单、多线程并发安全,支持多线程工作单元,支持多线程无工作单元,支持。。。
|
||||
// 用户体验优先,万金油模式,支持高并发。支持单、多线程并发安全,支持多线程工作单元,支持。。。
|
||||
// 不支持多线程无工作单元,应由工作单元统一管理(来自abp工作单元设计)
|
||||
// 请注意,如果requiresNew: true只有在没有工作单元内使用,嵌套子工作单元,默认值false即可
|
||||
// 自动在各个情况处理db客户端最优解之一
|
||||
int i = 3;
|
||||
@@ -78,7 +79,8 @@ namespace Yi.Abp.Application.Services
|
||||
{
|
||||
tasks.Add(Task.Run(async () =>
|
||||
{
|
||||
await sqlSugarRepository.InsertAsync(new BannerAggregateRoot { Name = "插入2" });
|
||||
//以下操作是错误的,不允许在新线程中,直接操作db,所有db操作应放在工作单元内,应由工作单元统一管理-来自abp工作单元设计
|
||||
//await sqlSugarRepository.InsertAsync(new BannerAggregateRoot { Name = "插入2" });
|
||||
using (var uow = UnitOfWorkManager.Begin(requiresNew: true, isTransactional: true))
|
||||
{
|
||||
await sqlSugarRepository.InsertAsync(new BannerAggregateRoot { Name = "插入1" });
|
||||
|
||||
@@ -72,6 +72,30 @@ namespace Yi.Abp.Web
|
||||
{
|
||||
private const string DefaultCorsPolicyName = "Default";
|
||||
|
||||
public override void PreConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
//动态Api-改进在pre中配置,启动更快
|
||||
PreConfigure<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");
|
||||
});
|
||||
}
|
||||
|
||||
public override Task ConfigureServicesAsync(ServiceConfigurationContext context)
|
||||
{
|
||||
var configuration = context.Services.GetConfiguration();
|
||||
@@ -98,6 +122,7 @@ namespace Yi.Abp.Web
|
||||
//配置错误处理显示详情
|
||||
Configure<AbpExceptionHandlingOptions>(options => { options.SendExceptionsDetailsToClients = true; });
|
||||
|
||||
|
||||
//动态Api
|
||||
Configure<AbpAspNetCoreMvcOptions>(options =>
|
||||
{
|
||||
|
||||
@@ -20,6 +20,7 @@ namespace Yi.Abp.Tool.Commands
|
||||
{
|
||||
application.OnExecute(() =>
|
||||
{
|
||||
Console.WriteLine("正在克隆,请耐心等待");
|
||||
StartCmd($"git clone {CloneAddress}");
|
||||
return 0;
|
||||
});
|
||||
|
||||
@@ -36,6 +36,9 @@ namespace Yi.Abp.Tool.Commands
|
||||
var soureOption = application.Option("-s|--soure", "模板来源,gitee模板库分支名称: 默认值`default`",
|
||||
CommandOptionType.SingleValue);
|
||||
|
||||
var dbmsOption = application.Option("-dbms|--dataBaseMs", "数据库类型,支持目前主流数据库",
|
||||
CommandOptionType.SingleValue);
|
||||
|
||||
var moduleNameArgument = application.Argument("moduleName", "模块名", (_) => { });
|
||||
|
||||
//子命令,new list
|
||||
@@ -58,6 +61,11 @@ namespace Yi.Abp.Tool.Commands
|
||||
|
||||
application.OnExecute(() =>
|
||||
{
|
||||
if (dbmsOption.HasValue())
|
||||
{
|
||||
Console.WriteLine($"检测到使用数据库类型-{dbmsOption.Value()},请在生成后,只需在配置文件中,更改DbConnOptions:Url及DbType即可,支持目前主流数据库20+");
|
||||
}
|
||||
|
||||
var path = string.Empty;
|
||||
if (pathOption.HasValue())
|
||||
{
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<Version>2.0.4</Version>
|
||||
<Version>2.0.5</Version>
|
||||
<Authors>橙子老哥</Authors>
|
||||
<Description>yi-framework框架配套工具</Description>
|
||||
<PackageProjectUrl>https://ccnetcore.com</PackageProjectUrl>
|
||||
|
||||
Reference in New Issue
Block a user