34 changed files with 240 additions and 416 deletions
@ -0,0 +1,9 @@ |
|||||
|
namespace Lion.AbpPro.AspNetCore.Options; |
||||
|
|
||||
|
public class AbpProAntiForgeryOptions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 是否启用
|
||||
|
/// </summary>
|
||||
|
public bool Enabled { get; set; } |
||||
|
} |
||||
@ -0,0 +1,9 @@ |
|||||
|
namespace Lion.AbpPro.AspNetCore.Options; |
||||
|
|
||||
|
public class AbpProCookieOptions |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// 名称
|
||||
|
/// </summary>
|
||||
|
public string Name { get; set; } = AbpProAspNetCoreConsts.DefaultCookieName; |
||||
|
} |
||||
@ -1,26 +1,26 @@ |
|||||
// namespace Swagger;
|
namespace Swagger; |
||||
//
|
|
||||
// /// <summary>
|
/// <summary>
|
||||
// /// swagger注释加载慢,把文档添加到缓存
|
/// swagger注释加载慢,把文档添加到缓存
|
||||
// /// </summary>
|
/// </summary>
|
||||
// [Dependency(ReplaceServices = true)]
|
[Dependency(ReplaceServices = true)] |
||||
// [ExposeServices(typeof(ISwaggerProvider))]
|
[ExposeServices(typeof(ISwaggerProvider))] |
||||
// public class CachingSwaggerProvider : ISwaggerProvider, ITransientDependency
|
public class CachingSwaggerProvider : ISwaggerProvider, ITransientDependency |
||||
// {
|
{ |
||||
// private static readonly ConcurrentDictionary<string, OpenApiDocument> _cache = new ConcurrentDictionary<string, OpenApiDocument>();
|
private static readonly ConcurrentDictionary<string, OpenApiDocument> _cache = new ConcurrentDictionary<string, OpenApiDocument>(); |
||||
//
|
|
||||
// private readonly SwaggerGenerator _swaggerGenerator;
|
private readonly SwaggerGenerator _swaggerGenerator; |
||||
//
|
|
||||
// public CachingSwaggerProvider(
|
public CachingSwaggerProvider( |
||||
// IOptions<SwaggerGeneratorOptions> optionsAccessor,
|
IOptions<SwaggerGeneratorOptions> optionsAccessor, |
||||
// IApiDescriptionGroupCollectionProvider apiDescriptionsProvider,
|
IApiDescriptionGroupCollectionProvider apiDescriptionsProvider, |
||||
// ISchemaGenerator schemaGenerator)
|
ISchemaGenerator schemaGenerator) |
||||
// {
|
{ |
||||
// _swaggerGenerator = new SwaggerGenerator(optionsAccessor.Value, apiDescriptionsProvider, schemaGenerator);
|
_swaggerGenerator = new SwaggerGenerator(optionsAccessor.Value, apiDescriptionsProvider, schemaGenerator); |
||||
// }
|
} |
||||
//
|
|
||||
// public OpenApiDocument GetSwagger(string documentName, string host = null, string basePath = null)
|
public OpenApiDocument GetSwagger(string documentName, string host = null, string basePath = null) |
||||
// {
|
{ |
||||
// return _cache.GetOrAdd(documentName, (_) => _swaggerGenerator.GetSwagger(documentName, host, basePath));
|
return _cache.GetOrAdd(documentName, (_) => _swaggerGenerator.GetSwagger(documentName, host, basePath)); |
||||
// }
|
} |
||||
// }
|
} |
||||
@ -1,21 +1,21 @@ |
|||||
// namespace Swagger;
|
namespace Swagger; |
||||
//
|
|
||||
// /// <summary>
|
/// <summary>
|
||||
// /// swagger 枚举映射,
|
/// swagger 枚举映射,
|
||||
// /// 原因:前端代理生成枚举是数字
|
/// 原因:前端代理生成枚举是数字
|
||||
// /// </summary>
|
/// </summary>
|
||||
// public class EnumSchemaFilter : ISchemaFilter
|
public class EnumSchemaFilter : ISchemaFilter |
||||
// {
|
{ |
||||
// public void Apply(OpenApiSchema schema, SchemaFilterContext context)
|
public void Apply(OpenApiSchema schema, SchemaFilterContext context) |
||||
// {
|
{ |
||||
// if (context.Type.IsEnum)
|
if (context.Type.IsEnum) |
||||
// {
|
{ |
||||
// var array = new OpenApiArray();
|
var array = new OpenApiArray(); |
||||
// array.AddRange(Enum.GetNames(context.Type).Select(n => new OpenApiString(n)));
|
array.AddRange(Enum.GetNames(context.Type).Select(n => new OpenApiString(n))); |
||||
// // NSwag
|
// NSwag
|
||||
// schema.Extensions.Add("x-enumNames", array);
|
schema.Extensions.Add("x-enumNames", array); |
||||
// // Openapi-generator
|
// Openapi-generator
|
||||
// schema.Extensions.Add("x-enum-varnames", array);
|
schema.Extensions.Add("x-enum-varnames", array); |
||||
// }
|
} |
||||
// }
|
} |
||||
// }
|
} |
||||
@ -1,48 +1,48 @@ |
|||||
// namespace Swagger;
|
namespace Swagger; |
||||
//
|
|
||||
// /// <summary>
|
/// <summary>
|
||||
// /// 在使用nswag的时候,原生默认的api导致生产的代理类存在问题
|
/// 在使用nswag的时候,原生默认的api导致生产的代理类存在问题
|
||||
// /// 所有隐藏原生的api,重写路由
|
/// 所有隐藏原生的api,重写路由
|
||||
// /// </summary>
|
/// </summary>
|
||||
// public class HiddenAbpDefaultApiFilter : IDocumentFilter
|
public class HiddenAbpDefaultApiFilter : IDocumentFilter |
||||
// {
|
{ |
||||
// public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
|
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) |
||||
// {
|
{ |
||||
// foreach (ApiDescription apiDescription in context.ApiDescriptions)
|
foreach (ApiDescription apiDescription in context.ApiDescriptions) |
||||
// {
|
{ |
||||
// if (apiDescription.TryGetMethodInfo(out MethodInfo method))
|
if (apiDescription.TryGetMethodInfo(out MethodInfo method)) |
||||
// {
|
{ |
||||
// string key = "/" + apiDescription.RelativePath;
|
string key = "/" + apiDescription.RelativePath; |
||||
// var reuslt = IsHidden(key);
|
var reuslt = IsHidden(key); |
||||
// if (reuslt) swaggerDoc.Paths.Remove(key);
|
if (reuslt) swaggerDoc.Paths.Remove(key); |
||||
// }
|
} |
||||
// }
|
} |
||||
// }
|
} |
||||
//
|
|
||||
// private bool IsHidden(string key)
|
private bool IsHidden(string key) |
||||
// {
|
{ |
||||
// var list = GetHiddenAbpDefaultApiList();
|
var list = GetHiddenAbpDefaultApiList(); |
||||
// foreach (var item in list)
|
foreach (var item in list) |
||||
// {
|
{ |
||||
// if (key.Contains(item)) return true;
|
if (key.Contains(item)) return true; |
||||
// }
|
} |
||||
//
|
|
||||
// return false;
|
return false; |
||||
// }
|
} |
||||
//
|
|
||||
// private List<string> GetHiddenAbpDefaultApiList()
|
private List<string> GetHiddenAbpDefaultApiList() |
||||
// {
|
{ |
||||
// return new List<string>() {
|
return new List<string>() { |
||||
// "/api/abp/multi-tenancy/tenants",
|
"/api/abp/multi-tenancy/tenants", |
||||
// "/api/account",
|
"/api/account", |
||||
// "/api/feature-management/features",
|
"/api/feature-management/features", |
||||
// "/api/permission-management/permissions",
|
"/api/permission-management/permissions", |
||||
// "/api/identity/my-profile",
|
"/api/identity/my-profile", |
||||
// "/api/identity",
|
"/api/identity", |
||||
// "/api/multi-tenancy/tenants",
|
"/api/multi-tenancy/tenants", |
||||
// "/api/setting-management/emailing",
|
"/api/setting-management/emailing", |
||||
// "/configuration",
|
"/configuration", |
||||
// "/outputcache"
|
"/outputcache" |
||||
// };
|
}; |
||||
// }
|
} |
||||
// }
|
} |
||||
@ -0,0 +1,67 @@ |
|||||
|
{ |
||||
|
"ConnectionStrings": { |
||||
|
//"Default": "Data Source=localhost;Port=3306;Database=LionAbpProDemo9;uid=root;pwd=1q2w3E*;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true" |
||||
|
"Default": "User ID=postgres;Password=1q2w3E*;Host=localhost;Port=5432;Database=LionAbpProDemo10;" |
||||
|
}, |
||||
|
"Hangfire": { |
||||
|
"Redis": { |
||||
|
"Host": "localhost:6379,password=1q2w3E*", |
||||
|
"DB": "2" |
||||
|
} |
||||
|
}, |
||||
|
"Redis": { |
||||
|
"Configuration": "localhost:6379,password=1q2w3E*,defaultdatabase=2" |
||||
|
}, |
||||
|
"Jwt": { |
||||
|
"Audience": "Lion.AbpPro", |
||||
|
"SecurityKey": "dzehzRz9a8asdfasfdadfasdfasdfafsdadfasbasdf=", |
||||
|
"Issuer": "Lion.AbpPro", |
||||
|
"ExpirationTime": 2 |
||||
|
}, |
||||
|
"Cap": { |
||||
|
"RabbitMq": { |
||||
|
"HostName": "localhost", |
||||
|
"UserName": "admin", |
||||
|
"Password": "1q2w3E*", |
||||
|
"Port": 5672 |
||||
|
} |
||||
|
}, |
||||
|
"ElasticSearch": { |
||||
|
"Host": "http://es.cn", |
||||
|
"UserName": "elastic", |
||||
|
"Password": "aVVhjQ95RP7nbwNy" |
||||
|
}, |
||||
|
"MiniProfiler": { |
||||
|
"Enabled": true, |
||||
|
"RouteBasePath": "/profiler" |
||||
|
}, |
||||
|
"Swagger": { |
||||
|
"Enabled": true |
||||
|
}, |
||||
|
"Audit": { |
||||
|
"Enabled": true, |
||||
|
"ApplicationName": "Lion.AbpPro" |
||||
|
}, |
||||
|
"Cors": { |
||||
|
"Enabled": true, |
||||
|
"CorsOrigins": "http://localhost:4200,http://localhost:4201" |
||||
|
}, |
||||
|
"Consul": { |
||||
|
"Enabled": false, |
||||
|
"ServiceUrl": "http://localhost:8500", |
||||
|
"ClientName": "Lion.AbpPro.Api", |
||||
|
"ClientAddress": "localhost", |
||||
|
"ClientPort": 44315, |
||||
|
"HealthUrl": "http://localhost:44315/health", |
||||
|
"DeregisterCriticalServiceAfter": 30, |
||||
|
"Interval": 30, |
||||
|
"Timeout": 30 |
||||
|
}, |
||||
|
"MultiTenancy": { |
||||
|
"Enabled": true |
||||
|
}, |
||||
|
"Preheat": { |
||||
|
"Enabled": true, |
||||
|
"RequestUrl": "http://localhost:44315/api/abp/application-configuration?IncludeLocalizationResources=false" |
||||
|
} |
||||
|
} |
||||
@ -1,6 +1,6 @@ |
|||||
{ |
{ |
||||
"ConnectionStrings": { |
"ConnectionStrings": { |
||||
// "Default": "Data Source=localhost;Port=3306;Database=LionAbpProDemo10;uid=root;pwd=1q2w3E*;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true" |
// "Default": "Data Source=localhost;Port=3306;Database=LionAbpProDemo10;uid=root;pwd=1q2w3E*;charset=utf8mb4;Allow User Variables=true;AllowLoadLocalInfile=true" |
||||
"Default": "User ID=postgres;Password=1q2w3E*;Host=localhost;Port=5432;Database=LionAbpProDemo10;" |
"Default": "User ID=postgres;Password=1q2w3E*;Host=localhost;Port=5432;Database=LionAbpProDemo1000;" |
||||
} |
} |
||||
} |
} |
||||
@ -1,7 +0,0 @@ |
|||||
namespace Lion.AbpPro.Users |
|
||||
{ |
|
||||
public interface IUserFreeSqlBasicRepository |
|
||||
{ |
|
||||
Task<List<UserOutput>> GetListAsync(); |
|
||||
} |
|
||||
} |
|
||||
@ -1,17 +0,0 @@ |
|||||
using Lion.AbpPro.Users; |
|
||||
using Lion.AbpPro.Users.Dto; |
|
||||
|
|
||||
namespace Lion.AbpPro.FreeSqlRepository |
|
||||
{ |
|
||||
public class UserFreeSqlBasicRepository : FreeSqlBasicRepository, IUserFreeSqlBasicRepository |
|
||||
{ |
|
||||
public async Task<List<UserOutput>> GetListAsync() |
|
||||
{ |
|
||||
var sql = "select id from AbpUsers"; |
|
||||
var result = await FreeSql.Select<UserOutput>() |
|
||||
.WithSql(sql) |
|
||||
.ToListAsync(); |
|
||||
return result; |
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,10 +0,0 @@ |
|||||
namespace Lion.AbpPro.FreeSqlRepository.Tests |
|
||||
{ |
|
||||
public abstract class AbpProFreeSqlRepositoryTestBase: AbpProTestBase<AbpProFreeSqlRepositoryTestModule> |
|
||||
{ |
|
||||
protected AbpProFreeSqlRepositoryTestBase() |
|
||||
{ |
|
||||
|
|
||||
} |
|
||||
} |
|
||||
} |
|
||||
@ -1,63 +0,0 @@ |
|||||
namespace Lion.AbpPro.FreeSqlReppsitory.Tests; |
|
||||
|
|
||||
[DependsOn( |
|
||||
typeof(AbpProTestBaseModule), |
|
||||
typeof(AbpProEntityFrameworkCoreModule), |
|
||||
typeof(AbpEntityFrameworkCoreSqliteModule), |
|
||||
typeof(AbpProFreeSqlModule) |
|
||||
)] |
|
||||
public class AbpProFreeSqlRepositoryTestModule : AbpModule |
|
||||
{ |
|
||||
private SqliteConnection _sqliteConnection; |
|
||||
private const string ConnectionString = "Data Source=:memory:"; |
|
||||
public override void ConfigureServices(ServiceConfigurationContext context) |
|
||||
{ |
|
||||
var freeSql = new FreeSql.FreeSqlBuilder() |
|
||||
.UseConnectionString(FreeSql.DataType.Sqlite, ConnectionString) |
|
||||
.UseAutoSyncStructure(true) |
|
||||
.Build(); |
|
||||
context.Services.AddSingleton<IFreeSql>(freeSql); |
|
||||
ConfigureInMemorySqlite(context.Services,freeSql); |
|
||||
|
|
||||
} |
|
||||
|
|
||||
private void ConfigureInMemorySqlite(IServiceCollection services,IFreeSql freeSql) |
|
||||
{ |
|
||||
_sqliteConnection = CreateDatabaseAndGetConnection(freeSql); |
|
||||
|
|
||||
services.Configure<AbpDbContextOptions>(options => |
|
||||
{ |
|
||||
options.Configure(context => |
|
||||
{ |
|
||||
context.DbContextOptions.UseSqlite(_sqliteConnection); |
|
||||
}); |
|
||||
}); |
|
||||
} |
|
||||
|
|
||||
public override void OnApplicationShutdown(ApplicationShutdownContext context) |
|
||||
{ |
|
||||
_sqliteConnection.Dispose(); |
|
||||
} |
|
||||
|
|
||||
private static SqliteConnection CreateDatabaseAndGetConnection(IFreeSql freeSql) |
|
||||
{ |
|
||||
var connection = new SqliteConnection(ConnectionString); |
|
||||
connection.Open(); |
|
||||
|
|
||||
var options = new DbContextOptionsBuilder<AbpProDbContext>() |
|
||||
.UseSqlite(connection) |
|
||||
.Options; |
|
||||
|
|
||||
using (var context = new AbpProDbContext(options)) |
|
||||
{ |
|
||||
foreach (var entityType in context.Model.GetEntityTypes()) |
|
||||
{ |
|
||||
freeSql.CodeFirst.SyncStructure(entityType.ClrType, entityType.GetTableName(), true); |
|
||||
} |
|
||||
context.GetService<IRelationalDatabaseCreator>().CreateTables(); |
|
||||
} |
|
||||
|
|
||||
return connection; |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
@ -1,18 +0,0 @@ |
|||||
// Global using directives
|
|
||||
|
|
||||
global using System.Threading.Tasks; |
|
||||
global using Lion.AbpPro.EntityFrameworkCore; |
|
||||
global using Lion.AbpPro.FreeSqlRepository; |
|
||||
global using Lion.AbpPro.FreeSqlReppsitory.Tests; |
|
||||
global using Lion.AbpPro.Users; |
|
||||
global using Microsoft.Data.Sqlite; |
|
||||
global using Microsoft.EntityFrameworkCore; |
|
||||
global using Microsoft.EntityFrameworkCore.Infrastructure; |
|
||||
global using Microsoft.EntityFrameworkCore.Storage; |
|
||||
global using Microsoft.Extensions.DependencyInjection; |
|
||||
global using Shouldly; |
|
||||
global using Volo.Abp; |
|
||||
global using Volo.Abp.EntityFrameworkCore; |
|
||||
global using Volo.Abp.EntityFrameworkCore.Sqlite; |
|
||||
global using Volo.Abp.Modularity; |
|
||||
global using Xunit; |
|
||||
@ -1,23 +0,0 @@ |
|||||
<Project Sdk="Microsoft.NET.Sdk"> |
|
||||
|
|
||||
<PropertyGroup> |
|
||||
<TargetFramework>net10.0</TargetFramework> |
|
||||
|
|
||||
<IsPackable>false</IsPackable> |
|
||||
|
|
||||
<RootNamespace>Lion.AbpPro.FreeSqlRepository.Tests</RootNamespace> |
|
||||
</PropertyGroup> |
|
||||
|
|
||||
<ItemGroup> |
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" /> |
|
||||
<PackageReference Include="FreeSql.Provider.Sqlite" /> |
|
||||
<PackageReference Include="Volo.Abp.EntityFrameworkCore.Sqlite" /> |
|
||||
</ItemGroup> |
|
||||
|
|
||||
<ItemGroup> |
|
||||
<ProjectReference Include="..\..\src\Lion.AbpPro.EntityFrameworkCore\Lion.AbpPro.EntityFrameworkCore.csproj" /> |
|
||||
<ProjectReference Include="..\..\src\Lion.AbpPro.FreeSqlRepository\Lion.AbpPro.FreeSqlRepository.csproj" /> |
|
||||
<ProjectReference Include="..\Lion.AbpPro.TestBase\Lion.AbpPro.TestBase.csproj" /> |
|
||||
</ItemGroup> |
|
||||
|
|
||||
</Project> |
|
||||
@ -1,21 +0,0 @@ |
|||||
namespace Lion.AbpPro.FreeSqlRepository.Tests.Users |
|
||||
{ |
|
||||
|
|
||||
|
|
||||
public class UserFreeSqlBasicRepository_Tests: AbpProFreeSqlRepositoryTestBase |
|
||||
{ |
|
||||
private readonly IUserFreeSqlBasicRepository _userFreeSqlBasicRepository; |
|
||||
public UserFreeSqlBasicRepository_Tests() |
|
||||
{ |
|
||||
_userFreeSqlBasicRepository = GetRequiredService<IUserFreeSqlBasicRepository>(); |
|
||||
} |
|
||||
|
|
||||
[Fact] |
|
||||
public async Task Should_NotThrow_ListAsyncTest() |
|
||||
{ |
|
||||
var result = await _userFreeSqlBasicRepository.GetListAsync(); |
|
||||
result.ShouldNotBeNull(); |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
} |
|
||||
Loading…
Reference in new issue