diff --git a/FastGithub.Configuration/TypeConverterBinder.cs b/FastGithub.Configuration/TypeConverterBinder.cs
index cf37c7e..f7dfd33 100644
--- a/FastGithub.Configuration/TypeConverterBinder.cs
+++ b/FastGithub.Configuration/TypeConverterBinder.cs
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
+using System.Diagnostics.CodeAnalysis;
using System.Globalization;
namespace FastGithub.Configuration
@@ -18,7 +19,7 @@ namespace FastGithub.Configuration
///
///
///
- public static void Bind(Func reader, Func writer)
+ public static void Bind<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(Func reader, Func writer)
{
binders[typeof(T)] = new Binder(reader, writer);
@@ -37,7 +38,7 @@ namespace FastGithub.Configuration
}
- private class Binder : Binder
+ private class Binder<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T> : Binder
{
private readonly Func reader;
private readonly Func writer;
@@ -60,7 +61,7 @@ namespace FastGithub.Configuration
}
- private class TypeConverter : TypeConverter
+ private class TypeConverter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T> : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
{
diff --git a/FastGithub.FlowAnalyze/FlowStatisticsContext.cs b/FastGithub.FlowAnalyze/FlowStatisticsContext.cs
new file mode 100644
index 0000000..18926e0
--- /dev/null
+++ b/FastGithub.FlowAnalyze/FlowStatisticsContext.cs
@@ -0,0 +1,9 @@
+using System.Text.Json.Serialization;
+
+namespace FastGithub.FlowAnalyze
+{
+ [JsonSerializable(typeof(FlowStatistics))]
+ public partial class FlowStatisticsContext : JsonSerializerContext
+ {
+ }
+}
diff --git a/FastGithub/AppOptions.cs b/FastGithub/AppOptions.cs
index b9a63a8..41c75b0 100644
--- a/FastGithub/AppOptions.cs
+++ b/FastGithub/AppOptions.cs
@@ -3,16 +3,16 @@
///
/// app选项
///
- public class AppOptions
+ public record AppOptions
{
///
/// 父进程id
///
- public int ParentProcessId { get; set; }
+ public int ParentProcessId { get; init; }
///
/// udp日志服务器端口
///
- public int UdpLoggerPort { get; set; }
+ public int UdpLoggerPort { get; init; }
}
}
diff --git a/FastGithub/Startup.cs b/FastGithub/Startup.cs
index a7ef3cb..16cc53f 100644
--- a/FastGithub/Startup.cs
+++ b/FastGithub/Startup.cs
@@ -9,8 +9,11 @@ using Microsoft.Extensions.Hosting;
using Serilog;
using Serilog.Sinks.Network;
using System;
+using System.Collections.Generic;
+using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Net;
+using System.Text.Json;
namespace FastGithub
{
@@ -87,6 +90,7 @@ namespace FastGithub
/// ÷
///
///
+ [DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(Dictionary))]
public static void ConfigureServices(this WebApplicationBuilder builder)
{
var services = builder.Services;
@@ -124,7 +128,8 @@ namespace FastGithub
app.MapGet("/flowStatistics", context =>
{
var flowStatistics = context.RequestServices.GetRequiredService().GetFlowStatistics();
- return context.Response.WriteAsJsonAsync(flowStatistics);
+ var json = JsonSerializer.Serialize(flowStatistics, FlowStatisticsContext.Default.FlowStatistics);
+ return context.Response.WriteAsync(json);
});
}
}