diff --git a/src/InterfaceForward.Api/InterfaceForward.Api.csproj b/src/InterfaceForward.Api/InterfaceForward.Api.csproj
index 94935ce..86801b8 100644
--- a/src/InterfaceForward.Api/InterfaceForward.Api.csproj
+++ b/src/InterfaceForward.Api/InterfaceForward.Api.csproj
@@ -15,17 +15,12 @@
-
+
-
-
-
-
-
diff --git a/src/InterfaceForward.Api/InterfaceForwardApiModule.cs b/src/InterfaceForward.Api/InterfaceForwardApiModule.cs
index ebfc3b1..93b7252 100644
--- a/src/InterfaceForward.Api/InterfaceForwardApiModule.cs
+++ b/src/InterfaceForward.Api/InterfaceForwardApiModule.cs
@@ -1,33 +1,53 @@
using Fake.AspNetCore;
+using Fake.AspNetCore.Mvc;
+using Fake.AspNetCore.Mvc.Conventions;
using Fake.Authorization;
-using Fake.Helpers;
+using Fake.Autofac;
using Fake.Modularity;
using InterfaceForward.Application;
using InterfaceForward.Application.Filters;
-using InterfaceForward.Repositories;
+using Microsoft.AspNetCore.Mvc;
namespace InterfaceForward.Api;
-[DependsOn(typeof(FakeAspNetCoreModule))]
-[DependsOn(typeof(FakeAuthorizationModule))]
-[DependsOn(typeof(InterfaceForwardRepositoriesModule))]
+[DependsOn(typeof(FakeAutofacModule))]
+[DependsOn(typeof(FakeAspNetCoreMvcModule))]
[DependsOn(typeof(InterfaceForwardApplicationModule))]
public class InterfaceForwardApiModule : FakeModule
{
+ private const string DefaultCorsPolicyName = "default";
public override void ConfigureServices(ServiceConfigurationContext context)
{
var services = context.Services;
+ var configuration = context.Services.GetConfiguration();
// Add services to the container.
services.AddProblemDetails();
- services.AddControllers(options =>
+ services.Configure(options =>
{
options.Filters.AddService();
- options.Filters.AddService();
+ options.Filters.AddService();
});
- services.AddSwagger();
+ services.Configure(options =>
+ {
+ options.AddAssembly(typeof(InterfaceForwardApplicationModule).Assembly);
+ });
+
+ services.AddUnifiedResultFilter();
+ services.AddFakeSwaggerGen();
+
+ services.AddCors(options =>
+ {
+ options.AddPolicy(DefaultCorsPolicyName, builder =>
+ {
+ builder.WithOrigins(configuration.GetSection("App:CorsOrigins").Get() ?? [])
+ .AllowAnyHeader()
+ .AllowAnyMethod()
+ .AllowCredentials();
+ });
+ });
}
public override void ConfigureApplication(ApplicationConfigureContext context)
@@ -36,19 +56,13 @@ public class InterfaceForwardApiModule : FakeModule
// Add Aspire default endpoints.
app.MapDefaultEndpoints();
-
- app.MapGet("/", () => "Hello World!");
// Configure the HTTP request pipeline.
- if (app.Environment.IsDevelopment())
- {
- app.UseSwagger();
- app.UseSwaggerUI(options =>
- {
- options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1");
- options.RoutePrefix = string.Empty;
- });
- }
+ app.UseFakeSwagger();
+
+ app.UseRouting();
+
+ app.UseCors(DefaultCorsPolicyName);
}
}
diff --git a/src/InterfaceForward.Api/Program.cs b/src/InterfaceForward.Api/Program.cs
index a7022db..edbdf93 100644
--- a/src/InterfaceForward.Api/Program.cs
+++ b/src/InterfaceForward.Api/Program.cs
@@ -1,12 +1,27 @@
using InterfaceForward.Api;
+using InterfaceForward.Api.Logs;
+using Serilog;
-var builder = WebApplication.CreateBuilder(args);
+try
+{
+ var builder = WebApplication.CreateSlimBuilder(args);
+ builder.UseSerilogDefault();
+ builder.WebHost.UseUrls(builder.Configuration.GetSection("App:Urls").Get() ?? []);
+ builder.Host.UseAutofac();
+ builder.Services.AddApplication();
-builder.Services.AddApplication();
+ // Add service defaults & Aspire components.
+ builder.AddServiceDefaults();
-// Add service defaults & Aspire components.
-builder.AddServiceDefaults();
-
-var app = builder.Build();
-app.InitializeApplication();
-app.Run();
\ No newline at end of file
+ var app = builder.Build();
+ app.InitializeApplication();
+ app.Run();
+}
+catch (Exception ex)
+{
+ Log.Fatal(ex, "G");
+}
+finally
+{
+ Log.CloseAndFlush();
+}
\ No newline at end of file
diff --git a/src/InterfaceForward.Api/appsettings.json b/src/InterfaceForward.Api/appsettings.json
index 10f68b8..91fe569 100644
--- a/src/InterfaceForward.Api/appsettings.json
+++ b/src/InterfaceForward.Api/appsettings.json
@@ -1,9 +1,30 @@
{
- "Logging": {
- "LogLevel": {
- "Default": "Information",
- "Microsoft.AspNetCore": "Warning"
- }
+ "Serilog": {
+ "MinimumLevel": {
+ "Default": "Debug",
+ "Override": {
+ "Microsoft.AspNetCore": "Debug"
+ }
+ },
+ "Enrich": [
+ "FromLogContext",
+ "WithMachineName",
+ "WithProcessId",
+ "WithThreadId"
+ ],
+ "WriteTo": [
+ {
+ "Name": "Console"
+ }
+ ]
},
- "AllowedHosts": "*"
+ "AllowedHosts": "*",
+ "App": {
+ "Urls": [
+ "http://*:8888"
+ ],
+ "CorsOrigins": [
+ "http://localhost:8888"
+ ]
+ }
}
diff --git a/src/InterfaceForward.Application.Contracts/ForwardCore/InterfaceRelayUnifyResultDto.cs b/src/InterfaceForward.Application.Contracts/ForwardCore/InterfaceRelayUnifyResultDto.cs
index e8f71bb..eb3fd9f 100644
--- a/src/InterfaceForward.Application.Contracts/ForwardCore/InterfaceRelayUnifyResultDto.cs
+++ b/src/InterfaceForward.Application.Contracts/ForwardCore/InterfaceRelayUnifyResultDto.cs
@@ -1,4 +1,4 @@
-using InterfaceForward.Domain.Shared.Dtos;
+using Fake.DomainDrivenDesign.Application.Dtos;
namespace InterfaceForward.Application.Contracts.ForwardCore;
diff --git a/src/InterfaceForward.Application.Contracts/InterfaceForward.Application.Contracts.csproj b/src/InterfaceForward.Application.Contracts/InterfaceForward.Application.Contracts.csproj
index 1b93815..9cd872b 100644
--- a/src/InterfaceForward.Application.Contracts/InterfaceForward.Application.Contracts.csproj
+++ b/src/InterfaceForward.Application.Contracts/InterfaceForward.Application.Contracts.csproj
@@ -9,8 +9,4 @@
-
-
-
-
diff --git a/src/InterfaceForward.Application/Filters/DefaultUnifiedResultHandler.cs b/src/InterfaceForward.Application/Filters/DefaultUnifiedResultHandler.cs
deleted file mode 100644
index b370989..0000000
--- a/src/InterfaceForward.Application/Filters/DefaultUnifiedResultHandler.cs
+++ /dev/null
@@ -1,57 +0,0 @@
-using InterfaceForward.Domain.Shared.Dtos;
-using Microsoft.AspNetCore.Mvc;
-using Microsoft.AspNetCore.Mvc.Filters;
-
-namespace InterfaceForward.Application.Filters;
-
-public class DefaultUnifiedResultHandler : IUnifiedResultHandler
-{
- public void HandleActionResult(ResultExecutingContext context)
- {
- // void、Task会被包装成EmptyResult
- if (context.Result is EmptyResult)
- {
- var res = new UnifyResultDto();
- context.Result = new ObjectResult(res);
-
- return;
- }
-
- // string、int、list以及自定义的模型,都会被包装成为ObjectResult
- if (context.Result is ObjectResult objectResult)
- {
- var value = objectResult.Value;
-
- // 已unified的无须再包装
- if (value is UnifyResultDto) return;
-
- var res = new UnifyResultDto