diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 38a22cb..b965c12 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -7,9 +7,9 @@ on:
branches: [ "main" ]
jobs:
- test-net9:
+ test-net10:
runs-on: ubuntu-latest
- container: mcr.microsoft.com/dotnet/sdk:9.0
+ container: mcr.microsoft.com/dotnet/sdk:10.0
steps:
- name: Checkout
diff --git a/.github/workflows/pack.yml b/.github/workflows/pack.yml
index 124a3e3..d117d42 100644
--- a/.github/workflows/pack.yml
+++ b/.github/workflows/pack.yml
@@ -13,7 +13,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v3
with:
- dotnet-version: '9'
+ dotnet-version: '10'
- name: Nuget Push
env:
nuget_key: ${{ secrets.NUGETAPIKEY }}
diff --git a/Directory.Build.props b/Directory.Build.props
index 6670e95..da814ca 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -1,7 +1,7 @@
- net9.0
+ net10.0
enable
enable
Cnblogs
diff --git a/src/Cnblogs.Architecture.Ddd.Cqrs.Abstractions/Cnblogs.Architecture.Ddd.Cqrs.Abstractions.csproj b/src/Cnblogs.Architecture.Ddd.Cqrs.Abstractions/Cnblogs.Architecture.Ddd.Cqrs.Abstractions.csproj
index ee6a8bb..a45f012 100644
--- a/src/Cnblogs.Architecture.Ddd.Cqrs.Abstractions/Cnblogs.Architecture.Ddd.Cqrs.Abstractions.csproj
+++ b/src/Cnblogs.Architecture.Ddd.Cqrs.Abstractions/Cnblogs.Architecture.Ddd.Cqrs.Abstractions.csproj
@@ -17,8 +17,8 @@
-
-
+
+
diff --git a/src/Cnblogs.Architecture.Ddd.Cqrs.AspNetCore/Cnblogs.Architecture.Ddd.Cqrs.AspNetCore.csproj b/src/Cnblogs.Architecture.Ddd.Cqrs.AspNetCore/Cnblogs.Architecture.Ddd.Cqrs.AspNetCore.csproj
index 76f3029..e0708ef 100644
--- a/src/Cnblogs.Architecture.Ddd.Cqrs.AspNetCore/Cnblogs.Architecture.Ddd.Cqrs.AspNetCore.csproj
+++ b/src/Cnblogs.Architecture.Ddd.Cqrs.AspNetCore/Cnblogs.Architecture.Ddd.Cqrs.AspNetCore.csproj
@@ -9,7 +9,7 @@
-
+
diff --git a/src/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent.csproj b/src/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent.csproj
index 99e1d98..d59db5e 100644
--- a/src/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent.csproj
+++ b/src/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent.csproj
@@ -27,4 +27,8 @@
CqrsVersionExtensions.cs
+
+
+
+
diff --git a/src/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent/InjectExtensions.cs b/src/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent/InjectExtensions.cs
index a8ed4e5..b21c658 100644
--- a/src/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent/InjectExtensions.cs
+++ b/src/Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent/InjectExtensions.cs
@@ -1,9 +1,8 @@
-using System.Net;
using System.Net.Http.Headers;
using Cnblogs.Architecture.Ddd.Cqrs.AspNetCore;
using Microsoft.Extensions.DependencyInjection;
-using Polly;
-using Polly.Extensions.Http;
+using Microsoft.Extensions.Http.Logging;
+using Microsoft.Extensions.Http.Resilience;
namespace Cnblogs.Architecture.Ddd.Cqrs.ServiceAgent;
@@ -17,22 +16,25 @@ public static class InjectExtensions
///
/// The .
/// The base uri for api.
- /// The polly policy for underlying httpclient.
+ /// Configure logging behavior.
+ /// The polly policy for underlying httpclient.
/// The type of service agent
///
public static IHttpClientBuilder AddServiceAgent(
this IServiceCollection services,
string baseUri,
- IAsyncPolicy? policy = null)
+ Action? loggingConfigure = null,
+ Action? pollyConfigure = null)
where TClient : class
{
- policy ??= GetDefaultPolicy();
- return services.AddHttpClient(
- h =>
- {
- h.BaseAddress = new Uri(baseUri);
- h.AddCqrsAcceptHeaders();
- }).AddPolicyHandler(policy);
+ var builder = services.AddHttpClient(h =>
+ {
+ h.BaseAddress = new Uri(baseUri);
+ h.AddCqrsAcceptHeaders();
+ });
+ builder.AddLogging(loggingConfigure);
+ builder.ApplyResilienceConfigure(pollyConfigure);
+ return builder;
}
///
@@ -40,24 +42,38 @@ public static IHttpClientBuilder AddServiceAgent(
///
/// The .
/// The base uri for api.
- /// The polly policy for underlying httpclient.
+ /// Configure logging behavior.
+ /// The polly policy for underlying httpclient.
/// The type of api client.
/// The type of service agent
///
public static IHttpClientBuilder AddServiceAgent(
this IServiceCollection services,
string baseUri,
- IAsyncPolicy? policy = null)
+ Action? loggingConfigure = null,
+ Action? pollyConfigure = null)
where TClient : class
where TImplementation : class, TClient
{
- policy ??= GetDefaultPolicy();
- return services.AddHttpClient(
- h =>
- {
- h.BaseAddress = new Uri(baseUri);
- h.AddCqrsAcceptHeaders();
- }).AddPolicyHandler(policy);
+ var builder = services.AddHttpClient(h =>
+ {
+ h.BaseAddress = new Uri(baseUri);
+ h.AddCqrsAcceptHeaders();
+ });
+ builder.AddLogging(loggingConfigure);
+ builder.ApplyResilienceConfigure(pollyConfigure);
+ return builder;
+ }
+
+ private static void AddLogging(this IHttpClientBuilder h, Action? configure = null)
+ {
+ h.AddExtendedHttpClientLogging(o =>
+ {
+ o.LogBody = false;
+ o.LogRequestStart = false;
+ o.BodySizeLimit = 2000;
+ configure?.Invoke(o);
+ });
}
private static void AddCqrsAcceptHeaders(this HttpClient h)
@@ -66,10 +82,15 @@ private static void AddCqrsAcceptHeaders(this HttpClient h)
h.DefaultRequestHeaders.AppendCurrentCqrsVersion();
}
- private static IAsyncPolicy GetDefaultPolicy()
+ private static void ApplyResilienceConfigure(
+ this IHttpClientBuilder builder,
+ Action? extraConfigure)
{
- return HttpPolicyExtensions.HandleTransientHttpError()
- .OrResult(msg => msg.StatusCode == HttpStatusCode.TooManyRequests)
- .WaitAndRetryAsync(3, _ => TimeSpan.FromMilliseconds(1500));
+ builder.AddStandardResilienceHandler(options =>
+ {
+ options.Retry.DisableForUnsafeHttpMethods();
+ options.Retry.MaxRetryAttempts = 3;
+ extraConfigure?.Invoke(options);
+ });
}
}
diff --git a/src/Cnblogs.Architecture.Ddd.EventBus.Abstractions/PublishIntegrationEventHostedService.cs b/src/Cnblogs.Architecture.Ddd.EventBus.Abstractions/PublishIntegrationEventHostedService.cs
index b760d53..c2ae517 100644
--- a/src/Cnblogs.Architecture.Ddd.EventBus.Abstractions/PublishIntegrationEventHostedService.cs
+++ b/src/Cnblogs.Architecture.Ddd.EventBus.Abstractions/PublishIntegrationEventHostedService.cs
@@ -9,7 +9,7 @@ namespace Cnblogs.Architecture.Ddd.EventBus.Abstractions;
///
/// The hosted service for publishing integration event at background.
///
-public sealed class PublishIntegrationEventHostedService : BackgroundService
+public sealed partial class PublishIntegrationEventHostedService : BackgroundService
{
private readonly EventBusOptions _options;
private readonly IServiceProvider _serviceProvider;
@@ -38,7 +38,7 @@ public PublishIntegrationEventHostedService(
///
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
- _logger.LogInformation("Integration event publisher running");
+ LogIntegrationEventPublisherStarted();
var watch = new Stopwatch();
var failureCounter = 0;
var successCounter = 0;
@@ -57,26 +57,18 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
if (sent > 0)
{
successCounter++;
- _logger.LogInformation(
- "Published {PublishedEventCount} events in {Duration} ms, resting count: {RestingEventCount}",
- sent,
- watch.ElapsedMilliseconds,
- afterCount);
+ LogEventsPublished(sent, watch.ElapsedMilliseconds, afterCount);
}
}
catch (Exception e)
{
failureCounter++;
- _logger.LogWarning(
- e,
- "Publish integration event failed, pending count: {Count}, failure count: {FailureCount}",
- _eventBuffer.Count,
- failureCounter);
+ LogPublishEventFailed(e, _eventBuffer.Count, failureCounter);
}
if (downgraded == false && failureCounter >= _options.FailureCountBeforeDowngrade)
{
- _logger.LogError("Integration event publisher downgraded");
+ LogIntegrationEventPublisherDowngraded();
downgraded = true;
currentTimer = failedTimer;
successCounter = 0;
@@ -87,7 +79,7 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
downgraded = false;
currentTimer = normalTimer;
failureCounter = 0;
- _logger.LogWarning("Integration event publisher recovered from downgrade");
+ LogIntegrationEventPublisherRecoveredFromDowngrade();
}
}
}
@@ -117,4 +109,19 @@ private async Task PublishEventAsync()
return publishedEventCount;
}
+
+ [LoggerMessage(LogLevel.Information, "Integration event publisher running")]
+ partial void LogIntegrationEventPublisherStarted();
+
+ [LoggerMessage(LogLevel.Information, "Published {PublishedEventCount} events in {Duration} ms, resting count: {RestingEventCount}")]
+ partial void LogEventsPublished(int publishedEventCount, long duration, int restingEventCount);
+
+ [LoggerMessage(LogLevel.Warning, "Publish integration event failed, pending count: {Count}, failure count: {FailureCount}")]
+ partial void LogPublishEventFailed(Exception e, int count, int failureCount);
+
+ [LoggerMessage(LogLevel.Error, "Integration event publisher downgraded")]
+ partial void LogIntegrationEventPublisherDowngraded();
+
+ [LoggerMessage(LogLevel.Warning, "Integration event publisher recovered from downgrade")]
+ partial void LogIntegrationEventPublisherRecoveredFromDowngrade();
}
diff --git a/src/Cnblogs.Architecture.Ddd.Infrastructure.CacheProviders.InMemory/Cnblogs.Architecture.Ddd.Infrastructure.CacheProviders.InMemory.csproj b/src/Cnblogs.Architecture.Ddd.Infrastructure.CacheProviders.InMemory/Cnblogs.Architecture.Ddd.Infrastructure.CacheProviders.InMemory.csproj
index ef7c884..ac4e6ad 100644
--- a/src/Cnblogs.Architecture.Ddd.Infrastructure.CacheProviders.InMemory/Cnblogs.Architecture.Ddd.Infrastructure.CacheProviders.InMemory.csproj
+++ b/src/Cnblogs.Architecture.Ddd.Infrastructure.CacheProviders.InMemory/Cnblogs.Architecture.Ddd.Infrastructure.CacheProviders.InMemory.csproj
@@ -9,7 +9,7 @@
-
+
diff --git a/src/Cnblogs.Architecture.Ddd.Infrastructure.Dapper/Cnblogs.Architecture.Ddd.Infrastructure.Dapper.csproj b/src/Cnblogs.Architecture.Ddd.Infrastructure.Dapper/Cnblogs.Architecture.Ddd.Infrastructure.Dapper.csproj
index 6ac3d2d..c5328f5 100644
--- a/src/Cnblogs.Architecture.Ddd.Infrastructure.Dapper/Cnblogs.Architecture.Ddd.Infrastructure.Dapper.csproj
+++ b/src/Cnblogs.Architecture.Ddd.Infrastructure.Dapper/Cnblogs.Architecture.Ddd.Infrastructure.Dapper.csproj
@@ -10,7 +10,7 @@
-
+
diff --git a/src/Cnblogs.Architecture.Ddd.Infrastructure.EntityFramework/Cnblogs.Architecture.Ddd.Infrastructure.EntityFramework.csproj b/src/Cnblogs.Architecture.Ddd.Infrastructure.EntityFramework/Cnblogs.Architecture.Ddd.Infrastructure.EntityFramework.csproj
index c3fe132..9305daa 100644
--- a/src/Cnblogs.Architecture.Ddd.Infrastructure.EntityFramework/Cnblogs.Architecture.Ddd.Infrastructure.EntityFramework.csproj
+++ b/src/Cnblogs.Architecture.Ddd.Infrastructure.EntityFramework/Cnblogs.Architecture.Ddd.Infrastructure.EntityFramework.csproj
@@ -9,7 +9,7 @@
-
+
diff --git a/test/Cnblogs.Architecture.IntegrationTests/CommandResponseHandlerTests.cs b/test/Cnblogs.Architecture.IntegrationTests/CommandResponseHandlerTests.cs
index 5146fd2..fb92aec 100644
--- a/test/Cnblogs.Architecture.IntegrationTests/CommandResponseHandlerTests.cs
+++ b/test/Cnblogs.Architecture.IntegrationTests/CommandResponseHandlerTests.cs
@@ -3,7 +3,6 @@
using System.Net.Http.Json;
using Cnblogs.Architecture.Ddd.Cqrs.Abstractions;
using Cnblogs.Architecture.Ddd.Cqrs.AspNetCore;
-using Cnblogs.Architecture.IntegrationTestProject;
using Cnblogs.Architecture.IntegrationTestProject.Application.Commands;
using Cnblogs.Architecture.IntegrationTestProject.Application.Errors;
using Cnblogs.Architecture.IntegrationTestProject.Application.Queries;
diff --git a/test/Cnblogs.Architecture.IntegrationTests/CqrsRouteMapperTests.cs b/test/Cnblogs.Architecture.IntegrationTests/CqrsRouteMapperTests.cs
index 53892a3..31a3a70 100644
--- a/test/Cnblogs.Architecture.IntegrationTests/CqrsRouteMapperTests.cs
+++ b/test/Cnblogs.Architecture.IntegrationTests/CqrsRouteMapperTests.cs
@@ -1,7 +1,6 @@
using System.Net;
using System.Net.Http.Json;
using Cnblogs.Architecture.Ddd.Infrastructure.Abstractions;
-using Cnblogs.Architecture.IntegrationTestProject;
using Cnblogs.Architecture.IntegrationTestProject.Application.Commands;
using Microsoft.AspNetCore.Mvc.Testing;
diff --git a/test/Cnblogs.Architecture.IntegrationTests/CustomJsonConverterTests.cs b/test/Cnblogs.Architecture.IntegrationTests/CustomJsonConverterTests.cs
index f331a56..f4f7cd6 100644
--- a/test/Cnblogs.Architecture.IntegrationTests/CustomJsonConverterTests.cs
+++ b/test/Cnblogs.Architecture.IntegrationTests/CustomJsonConverterTests.cs
@@ -1,7 +1,6 @@
using System.Net.Http.Json;
using System.Text;
using System.Text.Json;
-using Cnblogs.Architecture.IntegrationTestProject;
using Cnblogs.Architecture.IntegrationTestProject.Models;
using Microsoft.AspNetCore.Mvc.Testing;
diff --git a/test/Cnblogs.Architecture.IntegrationTests/CustomModelBinderTests.cs b/test/Cnblogs.Architecture.IntegrationTests/CustomModelBinderTests.cs
index f00288d..a3f9e0b 100644
--- a/test/Cnblogs.Architecture.IntegrationTests/CustomModelBinderTests.cs
+++ b/test/Cnblogs.Architecture.IntegrationTests/CustomModelBinderTests.cs
@@ -1,8 +1,6 @@
using System.Net;
using System.Net.Http.Json;
using Cnblogs.Architecture.Ddd.Infrastructure.Abstractions;
-using Cnblogs.Architecture.IntegrationTestProject;
-
using Microsoft.AspNetCore.Mvc.Testing;
namespace Cnblogs.Architecture.IntegrationTests;
diff --git a/test/Cnblogs.Architecture.IntegrationTests/IntegrationEventPublishTests.cs b/test/Cnblogs.Architecture.IntegrationTests/IntegrationEventPublishTests.cs
index a5e8874..960c943 100644
--- a/test/Cnblogs.Architecture.IntegrationTests/IntegrationEventPublishTests.cs
+++ b/test/Cnblogs.Architecture.IntegrationTests/IntegrationEventPublishTests.cs
@@ -1,7 +1,6 @@
using System.Net;
using System.Net.Http.Json;
using Cnblogs.Architecture.Ddd.EventBus.Abstractions;
-using Cnblogs.Architecture.IntegrationTestProject;
using Cnblogs.Architecture.IntegrationTestProject.Payloads;
using Cnblogs.Architecture.TestIntegrationEvents;
using Microsoft.AspNetCore.Mvc.Testing;
diff --git a/test/Cnblogs.Architecture.IntegrationTests/IntegrationTestFactory.cs b/test/Cnblogs.Architecture.IntegrationTests/IntegrationTestFactory.cs
index a278663..85fa30a 100644
--- a/test/Cnblogs.Architecture.IntegrationTests/IntegrationTestFactory.cs
+++ b/test/Cnblogs.Architecture.IntegrationTests/IntegrationTestFactory.cs
@@ -1,5 +1,4 @@
-using Cnblogs.Architecture.IntegrationTestProject;
-using Microsoft.AspNetCore.Mvc.Testing;
+using Microsoft.AspNetCore.Mvc.Testing;
namespace Cnblogs.Architecture.IntegrationTests;
diff --git a/test/Cnblogs.Architecture.IntegrationTests/MinimalApiTests.cs b/test/Cnblogs.Architecture.IntegrationTests/MinimalApiTests.cs
index c9f1a06..931be7a 100644
--- a/test/Cnblogs.Architecture.IntegrationTests/MinimalApiTests.cs
+++ b/test/Cnblogs.Architecture.IntegrationTests/MinimalApiTests.cs
@@ -1,4 +1,3 @@
-using Cnblogs.Architecture.IntegrationTestProject;
using Microsoft.AspNetCore.Mvc.Testing;
namespace Cnblogs.Architecture.IntegrationTests;
diff --git a/test/Cnblogs.Architecture.IntegrationTests/PaginationTests.cs b/test/Cnblogs.Architecture.IntegrationTests/PaginationTests.cs
index 49a5978..659d46b 100644
--- a/test/Cnblogs.Architecture.IntegrationTests/PaginationTests.cs
+++ b/test/Cnblogs.Architecture.IntegrationTests/PaginationTests.cs
@@ -1,4 +1,3 @@
-using Cnblogs.Architecture.IntegrationTestProject;
using Microsoft.AspNetCore.Mvc.Testing;
namespace Cnblogs.Architecture.IntegrationTests;
diff --git a/test/Cnblogs.Architecture.TestShared/Cnblogs.Architecture.TestShared.csproj b/test/Cnblogs.Architecture.TestShared/Cnblogs.Architecture.TestShared.csproj
index b95d0a5..0967413 100644
--- a/test/Cnblogs.Architecture.TestShared/Cnblogs.Architecture.TestShared.csproj
+++ b/test/Cnblogs.Architecture.TestShared/Cnblogs.Architecture.TestShared.csproj
@@ -1,6 +1,6 @@
-
+
diff --git a/test/Cnblogs.Architecture.UnitTests/Cnblogs.Architecture.UnitTests.csproj b/test/Cnblogs.Architecture.UnitTests/Cnblogs.Architecture.UnitTests.csproj
index b9b3ec6..0396df9 100644
--- a/test/Cnblogs.Architecture.UnitTests/Cnblogs.Architecture.UnitTests.csproj
+++ b/test/Cnblogs.Architecture.UnitTests/Cnblogs.Architecture.UnitTests.csproj
@@ -7,7 +7,7 @@
runtime; build; native; contentfiles; analyzers; buildtransitive
all
-
+
runtime; build; native; contentfiles; analyzers; buildtransitive
all