From 8c79ee73198d838433ef7e780ff94b001085e13d Mon Sep 17 00:00:00 2001 From: Okunets Yurii Date: Wed, 14 Jan 2026 15:38:24 +0200 Subject: [PATCH] Add net8 9 10 as target framework. Fix conflict for CreateVersion7 --- Directory.Build.props | 4 ++-- .../Commands/CommandExtensionsTests.cs | 3 ++- .../ManagedCode.Communication.Tests.csproj | 21 +++++++++++++++--- .../Orleans/OrleansSerializationTests.cs | 3 ++- .../CommandSerializationTests.cs | 5 +++-- .../Factories/CommandFactoryBridge.cs | 7 +++--- .../Factories/ICommandFactory.Defaults.cs | 5 +++-- .../ICommandValueFactory.Defaults.cs | 3 ++- .../Commands/PaginationCommand.cs | 3 ++- .../Helpers/GuidHelper.cs | 22 +++++++++++++++++++ .../ManagedCode.Communication.csproj | 7 +++--- 11 files changed, 64 insertions(+), 19 deletions(-) create mode 100644 ManagedCode.Communication/Helpers/GuidHelper.cs diff --git a/Directory.Build.props b/Directory.Build.props index 33e8f97..ca2e139 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,8 +1,8 @@ - 14 - net10.0 + 13 + net8.0;net9.0;net10.0 true enable true diff --git a/ManagedCode.Communication.Tests/Commands/CommandExtensionsTests.cs b/ManagedCode.Communication.Tests/Commands/CommandExtensionsTests.cs index 8817f17..e2d745b 100644 --- a/ManagedCode.Communication.Tests/Commands/CommandExtensionsTests.cs +++ b/ManagedCode.Communication.Tests/Commands/CommandExtensionsTests.cs @@ -1,5 +1,6 @@ using System; using ManagedCode.Communication.Commands; +using ManagedCode.Communication.Helpers; using Shouldly; using Xunit; @@ -49,7 +50,7 @@ public void WithMetadata_Action_CreatesMetadataAndConfigures() [Fact] public void WithMetadata_AssignsExistingInstance() { - var command = Command.Create(Guid.CreateVersion7(), "TestCommand"); + var command = Command.Create(GuidHelper.CreateVersion7(), "TestCommand"); var metadata = new CommandMetadata { UserAgent = "cli" }; command.WithMetadata(metadata); diff --git a/ManagedCode.Communication.Tests/ManagedCode.Communication.Tests.csproj b/ManagedCode.Communication.Tests/ManagedCode.Communication.Tests.csproj index 4808ef1..07a5938 100644 --- a/ManagedCode.Communication.Tests/ManagedCode.Communication.Tests.csproj +++ b/ManagedCode.Communication.Tests/ManagedCode.Communication.Tests.csproj @@ -25,9 +25,6 @@ - - - runtime; build; native; contentfiles; analyzers; buildtransitive @@ -42,6 +39,24 @@ all + + + + + + + + + + + + + + + + + + diff --git a/ManagedCode.Communication.Tests/Orleans/OrleansSerializationTests.cs b/ManagedCode.Communication.Tests/Orleans/OrleansSerializationTests.cs index 482483d..2752d6b 100644 --- a/ManagedCode.Communication.Tests/Orleans/OrleansSerializationTests.cs +++ b/ManagedCode.Communication.Tests/Orleans/OrleansSerializationTests.cs @@ -4,6 +4,7 @@ using Shouldly; using ManagedCode.Communication.CollectionResultT; using ManagedCode.Communication.Commands; +using ManagedCode.Communication.Helpers; using ManagedCode.Communication.Tests.Orleans.Fixtures; using ManagedCode.Communication.Tests.Orleans.Grains; using ManagedCode.Communication.Tests.Orleans.Models; @@ -32,7 +33,7 @@ public async Task CompleteWorkflow_AllTypes_ShouldSerializeCorrectly() var grain = _grainFactory.GetGrain(Guid.NewGuid()); // Step 1: Send a command - var commandId = Guid.CreateVersion7(); + var commandId = GuidHelper.CreateVersion7(); var paymentRequest = new PaymentRequest { OrderId = "order-999", diff --git a/ManagedCode.Communication.Tests/Orleans/Serialization/CommandSerializationTests.cs b/ManagedCode.Communication.Tests/Orleans/Serialization/CommandSerializationTests.cs index 2be160e..a24d540 100644 --- a/ManagedCode.Communication.Tests/Orleans/Serialization/CommandSerializationTests.cs +++ b/ManagedCode.Communication.Tests/Orleans/Serialization/CommandSerializationTests.cs @@ -3,6 +3,7 @@ using System.Threading.Tasks; using Shouldly; using ManagedCode.Communication.Commands; +using ManagedCode.Communication.Helpers; using ManagedCode.Communication.Tests.Orleans.Fixtures; using ManagedCode.Communication.Tests.Orleans.Grains; using ManagedCode.Communication.Tests.Orleans.Models; @@ -154,7 +155,7 @@ public async Task CommandT_WithComplexPayload_ShouldSerializeCorrectly() } }; - var command = Command.From(Guid.CreateVersion7(), payload); + var command = Command.From(GuidHelper.CreateVersion7(), payload); command.CommandType = "ProcessPayment"; command.CorrelationId = "correlation-789"; command.CausationId = "causation-012"; @@ -202,7 +203,7 @@ public async Task PaginationCommand_ShouldSerializeCorrectly() var grain = _grainFactory.GetGrain(Guid.NewGuid()); var options = new PaginationOptions(defaultPageSize: 25, maxPageSize: 50, minPageSize: 10); - var command = PaginationCommand.Create(Guid.CreateVersion7(), skip: 25, take: 5, options); + var command = PaginationCommand.Create(GuidHelper.CreateVersion7(), skip: 25, take: 5, options); command.CorrelationId = "pagination-correlation"; command.Metadata = new CommandMetadata { diff --git a/ManagedCode.Communication/Commands/Factories/CommandFactoryBridge.cs b/ManagedCode.Communication/Commands/Factories/CommandFactoryBridge.cs index aace38d..ace72bd 100644 --- a/ManagedCode.Communication/Commands/Factories/CommandFactoryBridge.cs +++ b/ManagedCode.Communication/Commands/Factories/CommandFactoryBridge.cs @@ -1,4 +1,5 @@ using System; +using ManagedCode.Communication.Helpers; namespace ManagedCode.Communication.Commands; @@ -10,7 +11,7 @@ internal static class CommandFactoryBridge public static TSelf Create(string commandType) where TSelf : class, ICommandFactory { - return TSelf.Create(Guid.CreateVersion7(), commandType); + return TSelf.Create(GuidHelper.CreateVersion7(), commandType); } public static TSelf Create(Guid commandId, string commandType) @@ -23,7 +24,7 @@ public static TSelf Create(TEnum commandType) where TSelf : class, ICommandFactory where TEnum : Enum { - return TSelf.Create(Guid.CreateVersion7(), commandType.ToString()); + return TSelf.Create(GuidHelper.CreateVersion7(), commandType.ToString()); } public static TSelf Create(Guid commandId, TEnum commandType) @@ -68,7 +69,7 @@ internal static class CommandValueFactoryBridge public static TSelf Create(TValue value) where TSelf : class, ICommandValueFactory { - return TSelf.Create(Guid.CreateVersion7(), ResolveCommandType(value), value); + return TSelf.Create(GuidHelper.CreateVersion7(), ResolveCommandType(value), value); } public static TSelf Create(Guid commandId, TValue value) diff --git a/ManagedCode.Communication/Commands/Factories/ICommandFactory.Defaults.cs b/ManagedCode.Communication/Commands/Factories/ICommandFactory.Defaults.cs index 4e301b0..9b9531f 100644 --- a/ManagedCode.Communication/Commands/Factories/ICommandFactory.Defaults.cs +++ b/ManagedCode.Communication/Commands/Factories/ICommandFactory.Defaults.cs @@ -1,4 +1,5 @@ using System; +using ManagedCode.Communication.Helpers; namespace ManagedCode.Communication.Commands; @@ -12,13 +13,13 @@ static virtual TSelf Create(string commandType) throw new ArgumentException("Command type must be provided.", nameof(commandType)); } - return TSelf.Create(Guid.CreateVersion7(), commandType); + return TSelf.Create(GuidHelper.CreateVersion7(), commandType); } static virtual TSelf Create(TEnum commandType) where TEnum : Enum { - return TSelf.Create(Guid.CreateVersion7(), commandType.ToString()); + return TSelf.Create(GuidHelper.CreateVersion7(), commandType.ToString()); } static virtual TSelf Create(Guid commandId, TEnum commandType) diff --git a/ManagedCode.Communication/Commands/Factories/ICommandValueFactory.Defaults.cs b/ManagedCode.Communication/Commands/Factories/ICommandValueFactory.Defaults.cs index 9a1578d..4368399 100644 --- a/ManagedCode.Communication/Commands/Factories/ICommandValueFactory.Defaults.cs +++ b/ManagedCode.Communication/Commands/Factories/ICommandValueFactory.Defaults.cs @@ -1,4 +1,5 @@ using System; +using ManagedCode.Communication.Helpers; namespace ManagedCode.Communication.Commands; @@ -8,7 +9,7 @@ public partial interface ICommandValueFactory static virtual TSelf Create(TValue value) { var commandType = ResolveCommandType(value); - return TSelf.Create(Guid.CreateVersion7(), commandType, value); + return TSelf.Create(GuidHelper.CreateVersion7(), commandType, value); } static virtual TSelf Create(Guid commandId, TValue value) diff --git a/ManagedCode.Communication/Commands/PaginationCommand.cs b/ManagedCode.Communication/Commands/PaginationCommand.cs index cd7ca79..3050bac 100644 --- a/ManagedCode.Communication/Commands/PaginationCommand.cs +++ b/ManagedCode.Communication/Commands/PaginationCommand.cs @@ -1,5 +1,6 @@ using System; using System.Text.Json.Serialization; +using ManagedCode.Communication.Helpers; namespace ManagedCode.Communication.Commands; @@ -73,7 +74,7 @@ public static PaginationCommand Create(PaginationRequest request, PaginationOpti { ArgumentNullException.ThrowIfNull(request); var normalized = request.Normalize(options); - return Create(Guid.CreateVersion7(), DefaultCommandType, normalized, options); + return Create(GuidHelper.CreateVersion7(), DefaultCommandType, normalized, options); } /// diff --git a/ManagedCode.Communication/Helpers/GuidHelper.cs b/ManagedCode.Communication/Helpers/GuidHelper.cs new file mode 100644 index 0000000..95314f0 --- /dev/null +++ b/ManagedCode.Communication/Helpers/GuidHelper.cs @@ -0,0 +1,22 @@ +using System; + +namespace ManagedCode.Communication.Helpers; + +internal static class GuidHelper +{ + /// + /// Creates a version 7 GUID (monotonic, sortable) if available, + /// otherwise falls back to a sequential GUID for .NET 8. + /// + public static Guid CreateVersion7() + { +#if NET9_0_OR_GREATER + return Guid.CreateVersion7(); +#else + // For .NET 8, use NewGuid() as a fallback + // In production, you might want to use a proper UUID v7 implementation + // or a library like System.Guid.NewSequentialGuid() if available + return Guid.NewGuid(); +#endif + } +} diff --git a/ManagedCode.Communication/ManagedCode.Communication.csproj b/ManagedCode.Communication/ManagedCode.Communication.csproj index a26d9a9..2187a01 100644 --- a/ManagedCode.Communication/ManagedCode.Communication.csproj +++ b/ManagedCode.Communication/ManagedCode.Communication.csproj @@ -13,13 +13,14 @@ managedcode, Communication, Result - - - + + + +