aot发布支持

This commit is contained in:
陈国伟 2022-09-20 14:55:55 +08:00
parent ef4ebf738a
commit bd70867481
4 changed files with 22 additions and 7 deletions

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization; using System.Globalization;
namespace FastGithub.Configuration namespace FastGithub.Configuration
@ -18,7 +19,7 @@ namespace FastGithub.Configuration
/// <typeparam name="T"></typeparam> /// <typeparam name="T"></typeparam>
/// <param name="reader"></param> /// <param name="reader"></param>
/// <param name="writer"></param> /// <param name="writer"></param>
public static void Bind<T>(Func<string, T?> reader, Func<T?, string?> writer) public static void Bind<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T>(Func<string, T?> reader, Func<T?, string?> writer)
{ {
binders[typeof(T)] = new Binder<T>(reader, writer); binders[typeof(T)] = new Binder<T>(reader, writer);
@ -37,7 +38,7 @@ namespace FastGithub.Configuration
} }
private class Binder<T> : Binder private class Binder<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T> : Binder
{ {
private readonly Func<string, T?> reader; private readonly Func<string, T?> reader;
private readonly Func<T?, string?> writer; private readonly Func<T?, string?> writer;
@ -60,7 +61,7 @@ namespace FastGithub.Configuration
} }
private class TypeConverter<T> : TypeConverter private class TypeConverter<[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] T> : TypeConverter
{ {
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType) public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
{ {

View File

@ -0,0 +1,9 @@
using System.Text.Json.Serialization;
namespace FastGithub.FlowAnalyze
{
[JsonSerializable(typeof(FlowStatistics))]
public partial class FlowStatisticsContext : JsonSerializerContext
{
}
}

View File

@ -3,16 +3,16 @@
/// <summary> /// <summary>
/// app选项 /// app选项
/// </summary> /// </summary>
public class AppOptions public record AppOptions
{ {
/// <summary> /// <summary>
/// 父进程id /// 父进程id
/// </summary> /// </summary>
public int ParentProcessId { get; set; } public int ParentProcessId { get; init; }
/// <summary> /// <summary>
/// udp日志服务器端口 /// udp日志服务器端口
/// </summary> /// </summary>
public int UdpLoggerPort { get; set; } public int UdpLoggerPort { get; init; }
} }
} }

View File

@ -9,8 +9,11 @@ using Microsoft.Extensions.Hosting;
using Serilog; using Serilog;
using Serilog.Sinks.Network; using Serilog.Sinks.Network;
using System; using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Text.Json;
namespace FastGithub namespace FastGithub
{ {
@ -87,6 +90,7 @@ namespace FastGithub
/// ÅäÖ÷þÎñ /// ÅäÖ÷þÎñ
/// </summary> /// </summary>
/// <param name="builder"></param> /// <param name="builder"></param>
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(Dictionary<string, DomainConfig>))]
public static void ConfigureServices(this WebApplicationBuilder builder) public static void ConfigureServices(this WebApplicationBuilder builder)
{ {
var services = builder.Services; var services = builder.Services;
@ -124,7 +128,8 @@ namespace FastGithub
app.MapGet("/flowStatistics", context => app.MapGet("/flowStatistics", context =>
{ {
var flowStatistics = context.RequestServices.GetRequiredService<IFlowAnalyzer>().GetFlowStatistics(); var flowStatistics = context.RequestServices.GetRequiredService<IFlowAnalyzer>().GetFlowStatistics();
return context.Response.WriteAsJsonAsync(flowStatistics); var json = JsonSerializer.Serialize(flowStatistics, FlowStatisticsContext.Default.FlowStatistics);
return context.Response.WriteAsync(json);
}); });
} }
} }