Skip to content

Commit ea28bb2

Browse files
committed
重构(project): 升级框架和依赖版本
升级目标框架至 net9.0,更新 TouchSocket 和 Hosting 相关依赖版本 调整 Program.cs 中变量声明为隐式类型,优化 Web API 配置方式 移除调试模式下的 Swagger 和浏览器启动功能 更新 Dockerfile 基础镜像至 .NET 9.0
1 parent 269b91b commit ea28bb2

File tree

6 files changed

+29
-40
lines changed

6 files changed

+29
-40
lines changed

frameworks/CSharp/touchsocket/src/TouchSocketHttp/Program.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ public class Program
1010
{
1111
private static async Task Main(string[] args)
1212
{
13-
int port = 8080;
14-
MyHttpService service = new MyHttpService();
13+
var port = 8080;
14+
var service = new MyHttpService();
1515

1616
await service.SetupAsync(new TouchSocketConfig()
1717
.SetListenIPHosts(port)
@@ -22,7 +22,6 @@ await service.SetupAsync(new TouchSocketConfig()
2222
options.SendPipeOptions = TransportOption.CreateSchedulerOptimizedPipeOptions();
2323
})
2424
.SetMaxCount(1000000)
25-
.SetBacklog(1000)
2625
.ConfigureContainer(a =>
2726
{
2827
a.AddConsoleLogger();
@@ -52,8 +51,8 @@ internal sealed class MyHttpSessionClient : HttpSessionClient
5251

5352
protected override async Task OnReceivedHttpRequest(HttpContext httpContext)
5453
{
55-
HttpRequest request = httpContext.Request;
56-
HttpResponse response = httpContext.Response;
54+
var request = httpContext.Request;
55+
var response = httpContext.Response;
5756

5857
switch (request.RelativeURL)
5958
{
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk.Worker">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<OutputType>Exe</OutputType>
77
<ImplicitUsings>enable</ImplicitUsings>
8-
<InvariantGlobalization>true</InvariantGlobalization>
9-
<!--<PublishAot>true</PublishAot>-->
108
<UserSecretsId>dotnet-TouchSocketWebApi-987c185f-10b1-452b-beb6-47d798a5a131</UserSecretsId>
11-
<ServerGarbageCollection>true</ServerGarbageCollection>
129
</PropertyGroup>
1310

1411
<ItemGroup>
15-
<PackageReference Include="TouchSocket.Http" Version="4.0.0-beta.80" />
12+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
13+
<PackageReference Include="TouchSocket.Hosting" Version="4.0.0-beta.112" />
14+
<PackageReference Include="TouchSocket.WebApi" Version="4.0.0-beta.112" />
1615
</ItemGroup>
1716
</Project>
17+

frameworks/CSharp/touchsocket/src/TouchSocketWebApi/Program.cs

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ public static void Main(string[] args)
2525
options.SendPipeOptions = TransportOption.CreateSchedulerOptimizedPipeOptions();
2626
})
2727
.SetMaxCount(1000000)
28-
.SetBacklog(1000)
2928
.ConfigureContainer(a =>
3029
{
3130
a.AddConsoleLogger();
@@ -36,28 +35,23 @@ public static void Main(string[] args)
3635
})
3736
.ConfigurePlugins(a =>
3837
{
39-
a.UseTcpSessionCheckClear();
40-
41-
a.UseWebApi()
42-
.ConfigureConverter(converter =>
38+
a.UseWebApi(options =>
4339
{
44-
converter.Clear();
45-
converter.AddSystemTextJsonSerializerFormatter(options =>
40+
options.ConfigureConverter(converter =>
4641
{
47-
options.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
42+
converter.Clear();
43+
converter.AddSystemTextJsonSerializerFormatter(jsonOptions =>
44+
{
45+
jsonOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
46+
});
4847
});
4948
});
5049

51-
#if DEBUG
52-
a.UseSwagger()
53-
.UseLaunchBrowser();
54-
#endif
55-
5650
a.UseDefaultHttpServicePlugin();
5751
});
5852
});
5953

60-
IHost host = builder.Build();
54+
var host = builder.Build();
6155
host.Run();
6256
}
6357
}
@@ -72,7 +66,7 @@ public partial class ApiServer : SingletonRpcServer
7266
[WebApi(Method = HttpMethodType.Get)]
7367
public async Task Plaintext(IWebApiCallContext callContext)
7468
{
75-
HttpResponse response = callContext.HttpContext.Response;
69+
var response = callContext.HttpContext.Response;
7670
response.SetStatus(200, "ok");
7771
response.Content = m_contentPlaintext;
7872
await response.AnswerAsync().ConfigureAwait(false);
@@ -86,7 +80,7 @@ public MyJson Json()
8680
}
8781
}
8882

89-
[JsonSerializable(typeof(MyJson))]//ʵ¼ÊÀàÐÍ1
83+
[JsonSerializable(typeof(MyJson))]
9084
internal partial class AppJsonSerializerContext : JsonSerializerContext
9185
{
9286

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
<Project Sdk="Microsoft.NET.Sdk.Worker">
22

33
<PropertyGroup>
4-
<TargetFramework>net8.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
7-
<InvariantGlobalization>true</InvariantGlobalization>
8-
<!--<PublishAot>true</PublishAot>-->
9-
<UserSecretsId>dotnet-TouchSocketWebApi-987c185f-10b1-452b-beb6-47d798a5a131</UserSecretsId>
10-
<ServerGarbageCollection>true</ServerGarbageCollection>
7+
<UserSecretsId>dotnet-WorkerService1-19b37b17-6043-4334-ad9a-9e0e3c670da3</UserSecretsId>
118
</PropertyGroup>
129

1310
<ItemGroup>
14-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
15-
<PackageReference Include="TouchSocket.Hosting" Version="4.0.0-beta.80" />
16-
<PackageReference Include="TouchSocket.WebApi" Version="4.0.0-beta.80" />
17-
<PackageReference Include="TouchSocket.WebApi.Swagger" Version="4.0.0-beta.80" />
11+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0" />
12+
<PackageReference Include="TouchSocket.Hosting" Version="4.0.0-beta.112" />
13+
<PackageReference Include="TouchSocket.WebApi" Version="4.0.0-beta.112" />
1814
</ItemGroup>
1915
</Project>

frameworks/CSharp/touchsocket/touchsocket-http.dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
1+
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
22
WORKDIR /app
33
COPY src/TouchSocketHttp .
44
RUN dotnet publish -c Release -o out
55

6-
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
6+
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
77

88
WORKDIR /app
99
COPY --from=build /app/out ./

frameworks/CSharp/touchsocket/touchsocket.dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
1+
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
22
WORKDIR /app
33
COPY src/TouchSocketWebApi .
44
RUN dotnet publish -c Release -o out
55

6-
FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
6+
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
77

88
WORKDIR /app
99
COPY --from=build /app/out ./

0 commit comments

Comments
 (0)