Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project>

<PropertyGroup>
<LangVersion>14</LangVersion>
<TargetFramework>net10.0</TargetFramework>
<LangVersion>13</LangVersion>
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
<EnableNETAnalyzers>true</EnableNETAnalyzers>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using ManagedCode.Communication.Commands;
using ManagedCode.Communication.Helpers;
using Shouldly;
using Xunit;

Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
<PackageReference Include="Microsoft.Orleans.TestingHost" Version="9.2.1"/>
<PackageReference Include="Shouldly" Version="4.3.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.1" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="10.0.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="10.0.0" />
<PackageReference Include="xunit" Version="2.9.3"/>
<PackageReference Include="xunit.runner.visualstudio" Version="3.1.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand All @@ -42,6 +39,24 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net8.0'">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="8.0.11" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.11" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="8.0.11" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net9.0'">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="9.0.1" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.1" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="9.0.1" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net10.0'">
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="10.0.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="10.0.0" />
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="10.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\ManagedCode.Communication.AspNetCore\ManagedCode.Communication.AspNetCore.csproj"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -32,7 +33,7 @@ public async Task CompleteWorkflow_AllTypes_ShouldSerializeCorrectly()
var grain = _grainFactory.GetGrain<ITestSerializationGrain>(Guid.NewGuid());

// Step 1: Send a command
var commandId = Guid.CreateVersion7();
var commandId = GuidHelper.CreateVersion7();
var paymentRequest = new PaymentRequest
{
OrderId = "order-999",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -154,7 +155,7 @@ public async Task CommandT_WithComplexPayload_ShouldSerializeCorrectly()
}
};

var command = Command<PaymentRequest>.From(Guid.CreateVersion7(), payload);
var command = Command<PaymentRequest>.From(GuidHelper.CreateVersion7(), payload);
command.CommandType = "ProcessPayment";
command.CorrelationId = "correlation-789";
command.CausationId = "causation-012";
Expand Down Expand Up @@ -202,7 +203,7 @@ public async Task PaginationCommand_ShouldSerializeCorrectly()
var grain = _grainFactory.GetGrain<ITestSerializationGrain>(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
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using ManagedCode.Communication.Helpers;

namespace ManagedCode.Communication.Commands;

Expand All @@ -10,7 +11,7 @@ internal static class CommandFactoryBridge
public static TSelf Create<TSelf>(string commandType)
where TSelf : class, ICommandFactory<TSelf>
{
return TSelf.Create(Guid.CreateVersion7(), commandType);
return TSelf.Create(GuidHelper.CreateVersion7(), commandType);
}

public static TSelf Create<TSelf>(Guid commandId, string commandType)
Expand All @@ -23,7 +24,7 @@ public static TSelf Create<TSelf, TEnum>(TEnum commandType)
where TSelf : class, ICommandFactory<TSelf>
where TEnum : Enum
{
return TSelf.Create(Guid.CreateVersion7(), commandType.ToString());
return TSelf.Create(GuidHelper.CreateVersion7(), commandType.ToString());
}

public static TSelf Create<TSelf, TEnum>(Guid commandId, TEnum commandType)
Expand Down Expand Up @@ -68,7 +69,7 @@ internal static class CommandValueFactoryBridge
public static TSelf Create<TSelf, TValue>(TValue value)
where TSelf : class, ICommandValueFactory<TSelf, TValue>
{
return TSelf.Create(Guid.CreateVersion7(), ResolveCommandType(value), value);
return TSelf.Create(GuidHelper.CreateVersion7(), ResolveCommandType(value), value);
}

public static TSelf Create<TSelf, TValue>(Guid commandId, TValue value)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using ManagedCode.Communication.Helpers;

namespace ManagedCode.Communication.Commands;

Expand All @@ -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>(TEnum commandType)
where TEnum : Enum
{
return TSelf.Create(Guid.CreateVersion7(), commandType.ToString());
return TSelf.Create(GuidHelper.CreateVersion7(), commandType.ToString());
}

static virtual TSelf Create<TEnum>(Guid commandId, TEnum commandType)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using ManagedCode.Communication.Helpers;

namespace ManagedCode.Communication.Commands;

Expand All @@ -8,7 +9,7 @@ public partial interface ICommandValueFactory<TSelf, TValue>
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)
Expand Down
3 changes: 2 additions & 1 deletion ManagedCode.Communication/Commands/PaginationCommand.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Text.Json.Serialization;
using ManagedCode.Communication.Helpers;

namespace ManagedCode.Communication.Commands;

Expand Down Expand Up @@ -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);
}

/// <summary>
Expand Down
22 changes: 22 additions & 0 deletions ManagedCode.Communication/Helpers/GuidHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;

namespace ManagedCode.Communication.Helpers;

internal static class GuidHelper
{
/// <summary>
/// Creates a version 7 GUID (monotonic, sortable) if available,
/// otherwise falls back to a sequential GUID for .NET 8.
/// </summary>
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
}
}
7 changes: 4 additions & 3 deletions ManagedCode.Communication/ManagedCode.Communication.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
<PackageTags>managedcode, Communication, Result</PackageTags>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="10.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="10.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="10.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.2" />
</ItemGroup>
<ItemGroup>
<InternalsVisibleTo Include="ManagedCode.Communication.AspNetCore"/>
<InternalsVisibleTo Include="ManagedCode.Communication.Orleans"/>
<InternalsVisibleTo Include="ManagedCode.Communication.Tests"/>
</ItemGroup>

</Project>
Loading