Skip to content

Commit d8a9281

Browse files
authored
chore: go net10 (#342)
* chore: go net10 * chore: update ci name
1 parent 64b9458 commit d8a9281

File tree

21 files changed

+84
-61
lines changed

21 files changed

+84
-61
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ on:
77
branches: [ "main" ]
88

99
jobs:
10-
test-net9:
10+
test-net10:
1111
runs-on: ubuntu-latest
12-
container: mcr.microsoft.com/dotnet/sdk:9.0
12+
container: mcr.microsoft.com/dotnet/sdk:10.0
1313

1414
steps:
1515
- name: Checkout

.github/workflows/pack.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- uses: actions/checkout@v3
1414
- uses: actions/setup-dotnet@v3
1515
with:
16-
dotnet-version: '9'
16+
dotnet-version: '10'
1717
- name: Nuget Push
1818
env:
1919
nuget_key: ${{ secrets.NUGETAPIKEY }}

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project>
22

33
<PropertyGroup>
4-
<TargetFramework>net9.0</TargetFramework>
4+
<TargetFramework>net10.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
<Authors>Cnblogs</Authors>

src/Cnblogs.Architecture.Ddd.Cqrs.Abstractions/Cnblogs.Architecture.Ddd.Cqrs.Abstractions.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717

1818
<ItemGroup>
1919
<PackageReference Include="Mapster" Version="7.4.0" />
20-
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.9" />
21-
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.9" />
20+
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.0-rc.2.25502.107" />
21+
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="10.0.0-rc.2.25502.107" />
2222
</ItemGroup>
2323

2424
</Project>

src/Cnblogs.Architecture.Ddd.Cqrs.AspNetCore/Cnblogs.Architecture.Ddd.Cqrs.AspNetCore.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<ItemGroup>
1010
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="8.1.0" />
1111
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
12-
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.9" />
12+
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0-rc.2.25502.107" />
1313
</ItemGroup>
1414

1515
<ItemGroup>

src/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,8 @@
2727
<Link>CqrsVersionExtensions.cs</Link>
2828
</Compile>
2929
</ItemGroup>
30+
31+
<ItemGroup>
32+
<PackageReference Include="Microsoft.Extensions.Http.Resilience" Version="9.10.0" />
33+
</ItemGroup>
3034
</Project>
Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
using System.Net;
21
using System.Net.Http.Headers;
32
using Cnblogs.Architecture.Ddd.Cqrs.AspNetCore;
43
using Microsoft.Extensions.DependencyInjection;
5-
using Polly;
6-
using Polly.Extensions.Http;
4+
using Microsoft.Extensions.Http.Logging;
5+
using Microsoft.Extensions.Http.Resilience;
76

87
namespace Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent;
98

@@ -17,47 +16,64 @@ public static class InjectExtensions
1716
/// </summary>
1817
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
1918
/// <param name="baseUri">The base uri for api.</param>
20-
/// <param name="policy">The polly policy for underlying httpclient.</param>
19+
/// <param name="loggingConfigure">Configure logging behavior.</param>
20+
/// <param name="pollyConfigure">The polly policy for underlying httpclient.</param>
2121
/// <typeparam name="TClient">The type of service agent</typeparam>
2222
/// <returns></returns>
2323
public static IHttpClientBuilder AddServiceAgent<TClient>(
2424
this IServiceCollection services,
2525
string baseUri,
26-
IAsyncPolicy<HttpResponseMessage>? policy = null)
26+
Action<LoggingOptions>? loggingConfigure = null,
27+
Action<HttpStandardResilienceOptions>? pollyConfigure = null)
2728
where TClient : class
2829
{
29-
policy ??= GetDefaultPolicy();
30-
return services.AddHttpClient<TClient>(
31-
h =>
32-
{
33-
h.BaseAddress = new Uri(baseUri);
34-
h.AddCqrsAcceptHeaders();
35-
}).AddPolicyHandler(policy);
30+
var builder = services.AddHttpClient<TClient>(h =>
31+
{
32+
h.BaseAddress = new Uri(baseUri);
33+
h.AddCqrsAcceptHeaders();
34+
});
35+
builder.AddLogging(loggingConfigure);
36+
builder.ApplyResilienceConfigure(pollyConfigure);
37+
return builder;
3638
}
3739

3840
/// <summary>
3941
/// Inject a service agent to services.
4042
/// </summary>
4143
/// <param name="services">The <see cref="IServiceCollection"/>.</param>
4244
/// <param name="baseUri">The base uri for api.</param>
43-
/// <param name="policy">The polly policy for underlying httpclient.</param>
45+
/// <param name="loggingConfigure">Configure logging behavior.</param>
46+
/// <param name="pollyConfigure">The polly policy for underlying httpclient.</param>
4447
/// <typeparam name="TClient">The type of api client.</typeparam>
4548
/// <typeparam name="TImplementation">The type of service agent</typeparam>
4649
/// <returns></returns>
4750
public static IHttpClientBuilder AddServiceAgent<TClient, TImplementation>(
4851
this IServiceCollection services,
4952
string baseUri,
50-
IAsyncPolicy<HttpResponseMessage>? policy = null)
53+
Action<LoggingOptions>? loggingConfigure = null,
54+
Action<HttpStandardResilienceOptions>? pollyConfigure = null)
5155
where TClient : class
5256
where TImplementation : class, TClient
5357
{
54-
policy ??= GetDefaultPolicy();
55-
return services.AddHttpClient<TClient, TImplementation>(
56-
h =>
57-
{
58-
h.BaseAddress = new Uri(baseUri);
59-
h.AddCqrsAcceptHeaders();
60-
}).AddPolicyHandler(policy);
58+
var builder = services.AddHttpClient<TClient, TImplementation>(h =>
59+
{
60+
h.BaseAddress = new Uri(baseUri);
61+
h.AddCqrsAcceptHeaders();
62+
});
63+
builder.AddLogging(loggingConfigure);
64+
builder.ApplyResilienceConfigure(pollyConfigure);
65+
return builder;
66+
}
67+
68+
private static void AddLogging(this IHttpClientBuilder h, Action<LoggingOptions>? configure = null)
69+
{
70+
h.AddExtendedHttpClientLogging(o =>
71+
{
72+
o.LogBody = false;
73+
o.LogRequestStart = false;
74+
o.BodySizeLimit = 2000;
75+
configure?.Invoke(o);
76+
});
6177
}
6278

6379
private static void AddCqrsAcceptHeaders(this HttpClient h)
@@ -66,10 +82,15 @@ private static void AddCqrsAcceptHeaders(this HttpClient h)
6682
h.DefaultRequestHeaders.AppendCurrentCqrsVersion();
6783
}
6884

69-
private static IAsyncPolicy<HttpResponseMessage> GetDefaultPolicy()
85+
private static void ApplyResilienceConfigure(
86+
this IHttpClientBuilder builder,
87+
Action<HttpStandardResilienceOptions>? extraConfigure)
7088
{
71-
return HttpPolicyExtensions.HandleTransientHttpError()
72-
.OrResult(msg => msg.StatusCode == HttpStatusCode.TooManyRequests)
73-
.WaitAndRetryAsync(3, _ => TimeSpan.FromMilliseconds(1500));
89+
builder.AddStandardResilienceHandler(options =>
90+
{
91+
options.Retry.DisableForUnsafeHttpMethods();
92+
options.Retry.MaxRetryAttempts = 3;
93+
extraConfigure?.Invoke(options);
94+
});
7495
}
7596
}

src/Cnblogs.Architecture.Ddd.EventBus.Abstractions/PublishIntegrationEventHostedService.cs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Cnblogs.Architecture.Ddd.EventBus.Abstractions;
99
/// <summary>
1010
/// The hosted service for publishing integration event at background.
1111
/// </summary>
12-
public sealed class PublishIntegrationEventHostedService : BackgroundService
12+
public sealed partial class PublishIntegrationEventHostedService : BackgroundService
1313
{
1414
private readonly EventBusOptions _options;
1515
private readonly IServiceProvider _serviceProvider;
@@ -38,7 +38,7 @@ public PublishIntegrationEventHostedService(
3838
/// <inheritdoc />
3939
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
4040
{
41-
_logger.LogInformation("Integration event publisher running");
41+
LogIntegrationEventPublisherStarted();
4242
var watch = new Stopwatch();
4343
var failureCounter = 0;
4444
var successCounter = 0;
@@ -57,26 +57,18 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
5757
if (sent > 0)
5858
{
5959
successCounter++;
60-
_logger.LogInformation(
61-
"Published {PublishedEventCount} events in {Duration} ms, resting count: {RestingEventCount}",
62-
sent,
63-
watch.ElapsedMilliseconds,
64-
afterCount);
60+
LogEventsPublished(sent, watch.ElapsedMilliseconds, afterCount);
6561
}
6662
}
6763
catch (Exception e)
6864
{
6965
failureCounter++;
70-
_logger.LogWarning(
71-
e,
72-
"Publish integration event failed, pending count: {Count}, failure count: {FailureCount}",
73-
_eventBuffer.Count,
74-
failureCounter);
66+
LogPublishEventFailed(e, _eventBuffer.Count, failureCounter);
7567
}
7668

7769
if (downgraded == false && failureCounter >= _options.FailureCountBeforeDowngrade)
7870
{
79-
_logger.LogError("Integration event publisher downgraded");
71+
LogIntegrationEventPublisherDowngraded();
8072
downgraded = true;
8173
currentTimer = failedTimer;
8274
successCounter = 0;
@@ -87,7 +79,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
8779
downgraded = false;
8880
currentTimer = normalTimer;
8981
failureCounter = 0;
90-
_logger.LogWarning("Integration event publisher recovered from downgrade");
82+
LogIntegrationEventPublisherRecoveredFromDowngrade();
9183
}
9284
}
9385
}
@@ -117,4 +109,19 @@ private async Task<int> PublishEventAsync()
117109

118110
return publishedEventCount;
119111
}
112+
113+
[LoggerMessage(LogLevel.Information, "Integration event publisher running")]
114+
partial void LogIntegrationEventPublisherStarted();
115+
116+
[LoggerMessage(LogLevel.Information, "Published {PublishedEventCount} events in {Duration} ms, resting count: {RestingEventCount}")]
117+
partial void LogEventsPublished(int publishedEventCount, long duration, int restingEventCount);
118+
119+
[LoggerMessage(LogLevel.Warning, "Publish integration event failed, pending count: {Count}, failure count: {FailureCount}")]
120+
partial void LogPublishEventFailed(Exception e, int count, int failureCount);
121+
122+
[LoggerMessage(LogLevel.Error, "Integration event publisher downgraded")]
123+
partial void LogIntegrationEventPublisherDowngraded();
124+
125+
[LoggerMessage(LogLevel.Warning, "Integration event publisher recovered from downgrade")]
126+
partial void LogIntegrationEventPublisherRecoveredFromDowngrade();
120127
}

src/Cnblogs.Architecture.Ddd.Infrastructure.CacheProviders.InMemory/Cnblogs.Architecture.Ddd.Infrastructure.CacheProviders.InMemory.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<ItemGroup>
1010
<ProjectReference Include="..\Cnblogs.Architecture.Ddd.Cqrs.DependencyInjection\Cnblogs.Architecture.Ddd.Cqrs.DependencyInjection.csproj"/>
1111
<ProjectReference Include="..\Cnblogs.Architecture.Ddd.Infrastructure.Abstractions\Cnblogs.Architecture.Ddd.Infrastructure.Abstractions.csproj"/>
12-
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.9" />
12+
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="10.0.0-rc.2.25502.107" />
1313
</ItemGroup>
1414

1515
</Project>

src/Cnblogs.Architecture.Ddd.Infrastructure.Dapper/Cnblogs.Architecture.Ddd.Infrastructure.Dapper.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
<ItemGroup>
1212
<PackageReference Include="Dapper" Version="2.1.66" />
13-
<PackageReference Include="Microsoft.Extensions.Options" Version="9.0.9" />
13+
<PackageReference Include="Microsoft.Extensions.Options" Version="10.0.0-rc.2.25502.107" />
1414
</ItemGroup>
1515

1616
</Project>

0 commit comments

Comments
 (0)