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;
|
|||
//
|
|||
// /// <summary>
|
|||
// /// swagger注释加载慢,把文档添加到缓存
|
|||
// /// </summary>
|
|||
// [Dependency(ReplaceServices = true)]
|
|||
// [ExposeServices(typeof(ISwaggerProvider))]
|
|||
// public class CachingSwaggerProvider : ISwaggerProvider, ITransientDependency
|
|||
// {
|
|||
// private static readonly ConcurrentDictionary<string, OpenApiDocument> _cache = new ConcurrentDictionary<string, OpenApiDocument>();
|
|||
//
|
|||
// private readonly SwaggerGenerator _swaggerGenerator;
|
|||
//
|
|||
// public CachingSwaggerProvider(
|
|||
// IOptions<SwaggerGeneratorOptions> optionsAccessor,
|
|||
// IApiDescriptionGroupCollectionProvider apiDescriptionsProvider,
|
|||
// ISchemaGenerator schemaGenerator)
|
|||
// {
|
|||
// _swaggerGenerator = new SwaggerGenerator(optionsAccessor.Value, apiDescriptionsProvider, schemaGenerator);
|
|||
// }
|
|||
//
|
|||
// public OpenApiDocument GetSwagger(string documentName, string host = null, string basePath = null)
|
|||
// {
|
|||
// return _cache.GetOrAdd(documentName, (_) => _swaggerGenerator.GetSwagger(documentName, host, basePath));
|
|||
// }
|
|||
// }
|
|||
namespace Swagger; |
|||
|
|||
/// <summary>
|
|||
/// swagger注释加载慢,把文档添加到缓存
|
|||
/// </summary>
|
|||
[Dependency(ReplaceServices = true)] |
|||
[ExposeServices(typeof(ISwaggerProvider))] |
|||
public class CachingSwaggerProvider : ISwaggerProvider, ITransientDependency |
|||
{ |
|||
private static readonly ConcurrentDictionary<string, OpenApiDocument> _cache = new ConcurrentDictionary<string, OpenApiDocument>(); |
|||
|
|||
private readonly SwaggerGenerator _swaggerGenerator; |
|||
|
|||
public CachingSwaggerProvider( |
|||
IOptions<SwaggerGeneratorOptions> optionsAccessor, |
|||
IApiDescriptionGroupCollectionProvider apiDescriptionsProvider, |
|||
ISchemaGenerator schemaGenerator) |
|||
{ |
|||
_swaggerGenerator = new SwaggerGenerator(optionsAccessor.Value, apiDescriptionsProvider, schemaGenerator); |
|||
} |
|||
|
|||
public OpenApiDocument GetSwagger(string documentName, string host = null, string basePath = null) |
|||
{ |
|||
return _cache.GetOrAdd(documentName, (_) => _swaggerGenerator.GetSwagger(documentName, host, basePath)); |
|||
} |
|||
} |
|||
@ -1,21 +1,21 @@ |
|||
// namespace Swagger;
|
|||
//
|
|||
// /// <summary>
|
|||
// /// swagger 枚举映射,
|
|||
// /// 原因:前端代理生成枚举是数字
|
|||
// /// </summary>
|
|||
// public class EnumSchemaFilter : ISchemaFilter
|
|||
// {
|
|||
// public void Apply(OpenApiSchema schema, SchemaFilterContext context)
|
|||
// {
|
|||
// if (context.Type.IsEnum)
|
|||
// {
|
|||
// var array = new OpenApiArray();
|
|||
// array.AddRange(Enum.GetNames(context.Type).Select(n => new OpenApiString(n)));
|
|||
// // NSwag
|
|||
// schema.Extensions.Add("x-enumNames", array);
|
|||
// // Openapi-generator
|
|||
// schema.Extensions.Add("x-enum-varnames", array);
|
|||
// }
|
|||
// }
|
|||
// }
|
|||
namespace Swagger; |
|||
|
|||
/// <summary>
|
|||
/// swagger 枚举映射,
|
|||
/// 原因:前端代理生成枚举是数字
|
|||
/// </summary>
|
|||
public class EnumSchemaFilter : ISchemaFilter |
|||
{ |
|||
public void Apply(OpenApiSchema schema, SchemaFilterContext context) |
|||
{ |
|||
if (context.Type.IsEnum) |
|||
{ |
|||
var array = new OpenApiArray(); |
|||
array.AddRange(Enum.GetNames(context.Type).Select(n => new OpenApiString(n))); |
|||
// NSwag
|
|||
schema.Extensions.Add("x-enumNames", array); |
|||
// Openapi-generator
|
|||
schema.Extensions.Add("x-enum-varnames", array); |
|||
} |
|||
} |
|||
} |
|||
@ -1,48 +1,48 @@ |
|||
// namespace Swagger;
|
|||
//
|
|||
// /// <summary>
|
|||
// /// 在使用nswag的时候,原生默认的api导致生产的代理类存在问题
|
|||
// /// 所有隐藏原生的api,重写路由
|
|||
// /// </summary>
|
|||
// public class HiddenAbpDefaultApiFilter : IDocumentFilter
|
|||
// {
|
|||
// public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
|
|||
// {
|
|||
// foreach (ApiDescription apiDescription in context.ApiDescriptions)
|
|||
// {
|
|||
// if (apiDescription.TryGetMethodInfo(out MethodInfo method))
|
|||
// {
|
|||
// string key = "/" + apiDescription.RelativePath;
|
|||
// var reuslt = IsHidden(key);
|
|||
// if (reuslt) swaggerDoc.Paths.Remove(key);
|
|||
// }
|
|||
// }
|
|||
// }
|
|||
//
|
|||
// private bool IsHidden(string key)
|
|||
// {
|
|||
// var list = GetHiddenAbpDefaultApiList();
|
|||
// foreach (var item in list)
|
|||
// {
|
|||
// if (key.Contains(item)) return true;
|
|||
// }
|
|||
//
|
|||
// return false;
|
|||
// }
|
|||
//
|
|||
// private List<string> GetHiddenAbpDefaultApiList()
|
|||
// {
|
|||
// return new List<string>() {
|
|||
// "/api/abp/multi-tenancy/tenants",
|
|||
// "/api/account",
|
|||
// "/api/feature-management/features",
|
|||
// "/api/permission-management/permissions",
|
|||
// "/api/identity/my-profile",
|
|||
// "/api/identity",
|
|||
// "/api/multi-tenancy/tenants",
|
|||
// "/api/setting-management/emailing",
|
|||
// "/configuration",
|
|||
// "/outputcache"
|
|||
// };
|
|||
// }
|
|||
// }
|
|||
namespace Swagger; |
|||
|
|||
/// <summary>
|
|||
/// 在使用nswag的时候,原生默认的api导致生产的代理类存在问题
|
|||
/// 所有隐藏原生的api,重写路由
|
|||
/// </summary>
|
|||
public class HiddenAbpDefaultApiFilter : IDocumentFilter |
|||
{ |
|||
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context) |
|||
{ |
|||
foreach (ApiDescription apiDescription in context.ApiDescriptions) |
|||
{ |
|||
if (apiDescription.TryGetMethodInfo(out MethodInfo method)) |
|||
{ |
|||
string key = "/" + apiDescription.RelativePath; |
|||
var reuslt = IsHidden(key); |
|||
if (reuslt) swaggerDoc.Paths.Remove(key); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private bool IsHidden(string key) |
|||
{ |
|||
var list = GetHiddenAbpDefaultApiList(); |
|||
foreach (var item in list) |
|||
{ |
|||
if (key.Contains(item)) return true; |
|||
} |
|||
|
|||
return false; |
|||
} |
|||
|
|||
private List<string> GetHiddenAbpDefaultApiList() |
|||
{ |
|||
return new List<string>() { |
|||
"/api/abp/multi-tenancy/tenants", |
|||
"/api/account", |
|||
"/api/feature-management/features", |
|||
"/api/permission-management/permissions", |
|||
"/api/identity/my-profile", |
|||
"/api/identity", |
|||
"/api/multi-tenancy/tenants", |
|||
"/api/setting-management/emailing", |
|||
"/configuration", |
|||
"/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": { |
|||
// "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