namespace trojan_csharp.Models; using Interfaces; using Microsoft.AspNetCore.Connections; using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets; public static class KestrelExtensions { public static IServiceCollection AddSocketFactory(this IServiceCollection services) { // socket to pipe services.AddSingleton(static sp => { var logger = sp.GetRequiredService>(); var options = new SocketConnectionFactoryOptions(); return new SocketConnectionContextFactory(options, logger); }); return services; } public static IConnectionBuilder UseMiddleware(this IConnectionBuilder builder) where TMiddleware : IKestrelMiddleware { return builder.Use(next => ctx => ActivatorUtilities.GetServiceOrCreateInstance(builder.ApplicationServices).InvokeAsync(next, ctx)); } }