chore 抽象微服务基本类库
This commit is contained in:
@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Swashbuckle.AspNetCore.SwaggerUI;
|
||||
using Volo.Abp.Swashbuckle;
|
||||
|
||||
namespace KonSoft.Shared.Hosting.AspNetCore;
|
||||
|
||||
public static class AbpSwaggerUIBuilderExtensions
|
||||
{
|
||||
public static IApplicationBuilder UseAbpSwaggerWithCustomScriptUI(
|
||||
this IApplicationBuilder app,
|
||||
Action<SwaggerUIOptions>? setupAction = null)
|
||||
{
|
||||
var resolver = app.ApplicationServices.GetService<ISwaggerHtmlResolver>();
|
||||
|
||||
return app.UseSwaggerUI(options =>
|
||||
{
|
||||
options.InjectJavascript("ui/abp.js");
|
||||
options.InjectJavascript("ui/abp.swagger.js");
|
||||
options.InjectJavascript("ui/requestinterceptor.js");
|
||||
options.IndexStream = () => resolver?.Resolver();
|
||||
|
||||
setupAction?.Invoke(options);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Serilog;
|
||||
using Volo.Abp.Modularity;
|
||||
|
||||
namespace KonSoft.Shared.Hosting.AspNetCore;
|
||||
|
||||
public static class ApplicationBuilderHelper
|
||||
{
|
||||
public static async Task<WebApplication> BuildApplicationAsync<TStartupModule>(string[] args)
|
||||
where TStartupModule : IAbpModule
|
||||
{
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
builder.Host
|
||||
.AddAppSettingsSecretsJson()
|
||||
.UseAutofac()
|
||||
.UseSerilog();
|
||||
|
||||
await builder.AddApplicationAsync<TStartupModule>();
|
||||
return builder.Build();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,36 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<RootNamespace>KonSoft.Shared.Hosting.AspNetCore</RootNamespace>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\KonSoft.Shared.Hosting\KonSoft.Shared.Hosting.csproj" />
|
||||
<ProjectReference Include="..\KonSoft.Shared.Localization\KonSoft.Shared.Localization.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
|
||||
<PackageReference Include="Volo.Abp.AspNetCore.Serilog" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.AspNetCore.MultiTenancy" Version="8.3.4" />
|
||||
<PackageReference Include="Volo.Abp.Swashbuckle" Version="8.3.4" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="wwwroot\swagger\ui\requestinterceptor.js" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Include="wwwroot\swagger\ui\requestinterceptor.js">
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="wwwroot\swagger\ui\requestinterceptor.js" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@ -0,0 +1,11 @@
|
||||
using Volo.Abp.DependencyInjection;
|
||||
using Volo.Abp.Ui.Branding;
|
||||
|
||||
namespace KonSoft.Shared.Hosting.AspNetCore
|
||||
{
|
||||
[Dependency(ReplaceServices = true)]
|
||||
public class KonSoftBrandingProvider : DefaultBrandingProvider
|
||||
{
|
||||
public override string AppName => "KonSoft";
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,8 @@
|
||||
namespace KonSoft.Shared.Hosting.AspNetCore;
|
||||
|
||||
public static class KonSoftConsts
|
||||
{
|
||||
public const string AuthServerAudience = "KonSoft";
|
||||
public const string AnonymousUserClaimName = "anonymous_id";
|
||||
public const bool MultiTenancyEnabled = true;
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
using KonSoft.Shared.Localization;
|
||||
using Volo.Abp.AspNetCore.Serilog;
|
||||
using Volo.Abp.Modularity;
|
||||
using Volo.Abp.MultiTenancy;
|
||||
using Volo.Abp.Swashbuckle;
|
||||
using Volo.Abp.VirtualFileSystem;
|
||||
|
||||
namespace KonSoft.Shared.Hosting.AspNetCore
|
||||
{
|
||||
[DependsOn(
|
||||
typeof(KonSoftSharedLocalizationModule),
|
||||
typeof(KonSoftSharedHostingModule),
|
||||
typeof(AbpAspNetCoreSerilogModule),
|
||||
typeof(AbpSwashbuckleModule),
|
||||
typeof(AbpMultiTenancyModule)
|
||||
)]
|
||||
public class KonSoftSharedHostingAspNetCoreModule : AbpModule
|
||||
{
|
||||
public override void ConfigureServices(ServiceConfigurationContext context)
|
||||
{
|
||||
Configure<AbpVirtualFileSystemOptions>(options =>
|
||||
{
|
||||
options.FileSets.AddEmbedded<KonSoftSharedHostingAspNetCoreModule>("KonSoft.Shared.Hosting.AspNetCore");
|
||||
});
|
||||
|
||||
Configure<AbpMultiTenancyOptions>(options =>
|
||||
{
|
||||
options.IsEnabled = KonSoftConsts.MultiTenancyEnabled;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,24 @@
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace KonSoft.Shared.Hosting.AspNetCore;
|
||||
|
||||
public static class SerilogConfigurationHelper
|
||||
{
|
||||
public static void Configure(string applicationName)
|
||||
{
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
#if DEBUG
|
||||
.MinimumLevel.Debug()
|
||||
#else
|
||||
.MinimumLevel.Information()
|
||||
#endif
|
||||
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
|
||||
.MinimumLevel.Override("Microsoft.EntityFrameworkCore", LogEventLevel.Warning)
|
||||
.Enrich.FromLogContext()
|
||||
.Enrich.WithProperty("Application", $"{applicationName}")
|
||||
.WriteTo.Async(c => c.File("Logs/logs.txt"))
|
||||
.WriteTo.Async(c => c.Console())
|
||||
.CreateLogger();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Volo.Abp.Modularity;
|
||||
|
||||
namespace KonSoft.Shared.Hosting.AspNetCore;
|
||||
|
||||
public static class SwaggerConfigurationHelper
|
||||
{
|
||||
public static void ConfigureWithOidc(
|
||||
ServiceConfigurationContext context,
|
||||
string authority,
|
||||
string[] scopes,
|
||||
string apiTitle,
|
||||
string apiVersion = "v1",
|
||||
string apiName = "v1",
|
||||
string[]? flows = null,
|
||||
string? discoveryEndpoint = null
|
||||
)
|
||||
{
|
||||
context.Services.AddAbpSwaggerGenWithOidc(
|
||||
authority: authority,
|
||||
scopes: scopes,
|
||||
flows: flows,
|
||||
discoveryEndpoint: discoveryEndpoint,
|
||||
options =>
|
||||
{
|
||||
options.SwaggerDoc(apiName, new OpenApiInfo { Title = apiTitle, Version = apiVersion });
|
||||
options.DocInclusionPredicate((docName, description) => true);
|
||||
options.CustomSchemaIds(type => type.FullName);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
const originalFetch = window.fetch;
|
||||
|
||||
window.fetch = function (input, init) {
|
||||
if (init !== undefined && init.headers['RequestVerificationToken'] !== undefined) {
|
||||
delete init.headers['RequestVerificationToken'];
|
||||
}
|
||||
|
||||
return originalFetch.apply(this, arguments);
|
||||
};
|
||||
Reference in New Issue
Block a user