Skip to content
Closed
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
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<IsWindows>$([MSBuild]::IsOSPlatform('Windows'))</IsWindows>
<IsMainAuthor Condition="'$(EMAIL)' == 'michael@geekle.io'">true</IsMainAuthor>
<SkipSignAssembly>false</SkipSignAssembly>
<LangVersion>latest</LangVersion>
<LangVersion>preview</LangVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(CI)' == 'true'">
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,52 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<ProjectGuid>1e0bdf91-e7c7-4cb4-a39d-e1a5374c5602</ProjectGuid>
<SonarQubeTestProject>false</SonarQubeTestProject>
</PropertyGroup>

<PropertyGroup>
<Description>The Codebelt.Extensions.Xunit.Hosting namespace contains types that provides a uniform way of doing unit testing used in conjunction with Microsoft Dependency Injection. The namespace relates to the Xunit.Abstractions namespace.</Description>
<PackageTags>host-test class-fixture host-fixture microsoft dependency injection host configuration hosting-environment service-provider configure-services</PackageTags>
</PropertyGroup>

<ItemGroup Condition="$(TargetFramework.StartsWith('net9'))">
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0-rc.2.24473.5" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0-rc.2.24473.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.0-rc.2.24473.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.0-rc.2.24473.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0-rc.2.24473.5" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework.StartsWith('net8'))">
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework.StartsWith('netstandard2'))">
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="xunit.extensibility.core" Version="2.9.2" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Codebelt.Extensions.Xunit\Codebelt.Extensions.Xunit.csproj" />
</ItemGroup>
<PropertyGroup>
<ProjectGuid>1e0bdf91-e7c7-4cb4-a39d-e1a5374c5602</ProjectGuid>
<SonarQubeTestProject>false</SonarQubeTestProject>
</PropertyGroup>

<PropertyGroup>
<Description>The Codebelt.Extensions.Xunit.Hosting namespace contains types that provides a uniform way of doing unit testing used in conjunction with Microsoft Dependency Injection. The namespace relates to the Xunit.Abstractions namespace.</Description>
<PackageTags>host-test class-fixture host-fixture microsoft dependency injection host configuration hosting-environment service-provider configure-services</PackageTags>
</PropertyGroup>

<ItemGroup Condition="$(TargetFramework.StartsWith('net9'))">
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.0-rc.2.24473.5" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="9.0.0-rc.2.24473.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="9.0.0-rc.2.24473.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="9.0.0-rc.2.24473.5" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="9.0.0-rc.2.24473.5" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework.StartsWith('net8'))">
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.1" />
</ItemGroup>

<ItemGroup Condition="$(TargetFramework.StartsWith('netstandard2'))">
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.1.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.1.1" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Cuemon.Extensions.Threading" Version="9.0.0-preview.11" />
<PackageReference Include="xunit.extensibility.core" Version="2.9.2" />
</ItemGroup>

<ItemGroup>
<Using Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))" Alias="Lock" Include="System.Threading.Lock" />
<Using Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net9.0'))" Alias="Lock" Include="Backport.System.Threading.Lock" />
<Using Alias="LockFactory" Include="Backport.System.Threading.LockFactory" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Codebelt.Extensions.Xunit\Codebelt.Extensions.Xunit.csproj" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion src/Codebelt.Extensions.Xunit.Hosting/HostFixture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Codebelt.Extensions.Xunit.Hosting
/// <seealso cref="IHostFixture" />
public class HostFixture : IDisposable, IHostFixture
{
private readonly object _lock = new();
private readonly Lock _lock = LockFactory.Create();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Conditional compilation missing for Lock initialization.

The _lock field is initialized with LockFactory.Create() without being enclosed in a #if NET9_0_OR_GREATER directive. This change affects all target frameworks, potentially causing compatibility issues for projects not targeting .NET 9.0 or higher.

  • Enclose the Lock initialization within conditional compilation directives:

    #if NET9_0_OR_GREATER
        private readonly Lock _lock = LockFactory.Create();
    #else
        private readonly object _lock = new object();
    #endif
  • Verify that the Dispose method and any other usages of _lock are appropriately handled for both cases.

  • Update the class documentation to reflect the conditional use of Lock based on the .NET version.

🔗 Analysis chain

LGTM! Consider adding conditional compilation and updating documentation.

The change to use Lock instead of object for the _lock field aligns with the PR objective of switching to a more performant System.Threading.Lock on .NET 9.0+. This is likely to improve performance and provide more advanced locking capabilities.

To ensure this change is only applied for .NET 9.0 and above, consider wrapping it in a conditional compilation directive:

#if NET9_0_OR_GREATER
    private readonly Lock _lock = LockFactory.Create();
#else
    private readonly object _lock = new object();
#endif

Also, update the class documentation to mention this optimization for .NET 9.0+.

To verify the usage of System.Threading.Lock, run the following script:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify the usage of System.Threading.Lock
rg --type csharp "using System.Threading;" src/Codebelt.Extensions.Xunit.Hosting/HostFixture.cs
rg --type csharp "Lock " src/Codebelt.Extensions.Xunit.Hosting/HostFixture.cs

Length of output: 237


Script:

#!/bin/bash
# Check for conditional compilation around Lock initialization
rg --type csharp '#if NET9_0_OR_GREATER' src/Codebelt.Extensions.Xunit.Hosting/HostFixture.cs
rg --type csharp '#endif' src/Codebelt.Extensions.Xunit.Hosting/HostFixture.cs

Length of output: 222


Script:

#!/bin/bash
# Check if the Lock initialization is within the NET9_0_OR_GREATER conditional block
# Extract lines around the Lock initialization
rg --type csharp -C5 'private readonly Lock _lock = LockFactory\.Create\(\);' src/Codebelt.Extensions.Xunit.Hosting/HostFixture.cs

Length of output: 565


/// <summary>
/// Initializes a new instance of the <see cref="HostFixture"/> class.
Expand Down