From bd7086748152a681cf31d148f3343701a6cfafa6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E9=99=88=E5=9B=BD=E4=BC=9F?= <366193849@qq.com>
Date: Tue, 20 Sep 2022 14:55:55 +0800
Subject: [PATCH] =?UTF-8?q?aot=E5=8F=91=E5=B8=83=E6=94=AF=E6=8C=81?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
FastGithub.Configuration/TypeConverterBinder.cs | 7 ++++---
FastGithub.FlowAnalyze/FlowStatisticsContext.cs | 9 +++++++++
FastGithub/AppOptions.cs | 6 +++---
FastGithub/Startup.cs | 7 ++++++-
4 files changed, 22 insertions(+), 7 deletions(-)
create mode 100644 FastGithub.FlowAnalyze/FlowStatisticsContext.cs
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);
});
}
}