diff --git a/src/JT808.DotNetty/JT808.DotNetty.csproj b/src/JT808.DotNetty/JT808.DotNetty.csproj index d40f63f..608982c 100644 --- a/src/JT808.DotNetty/JT808.DotNetty.csproj +++ b/src/JT808.DotNetty/JT808.DotNetty.csproj @@ -10,6 +10,8 @@ + + diff --git a/src/JT808.DotNetty/JT808WebHostBuilderKestrelExtensions.cs b/src/JT808.DotNetty/JT808WebHostBuilderKestrelExtensions.cs new file mode 100644 index 0000000..dbcfc73 --- /dev/null +++ b/src/JT808.DotNetty/JT808WebHostBuilderKestrelExtensions.cs @@ -0,0 +1,41 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Server.Kestrel.Core; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Abstractions.Internal; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.DependencyInjection.Abstractions; +using System; +using System.Collections.Generic; +using System.Text; +using Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets; +using Microsoft.Extensions.DependencyInjection.Extensions; +using Microsoft.Extensions.Options; +using Microsoft.AspNetCore.Server.Kestrel.Core.Internal; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.AspNetCore.Hosting.Server; + +namespace JT808.DotNetty +{ + public static class JT808WebHostBuilderKestrelExtensions + { + /// + /// Specify Kestrel as the server to be used by the web host. + /// + /// + /// The Microsoft.AspNetCore.Hosting.IWebHostBuilder to configure. + /// + /// + /// The Microsoft.AspNetCore.Hosting.IWebHostBuilder. + /// + public static IHostBuilder UseKestrel(this IHostBuilder hostBuilder, Action options) + { + return hostBuilder.ConfigureServices((context,services) => + { + services.Configure(options); + // Don't override an already-configured transport + services.TryAddSingleton(); + services.AddTransient, KestrelServerOptionsSetup>(); + services.AddSingleton(); + }); + } + } +}