Skip to content

Commit

Permalink
Improve support to .NET Standard and .NET Framework (#3507)
Browse files Browse the repository at this point in the history
* Improve support to .NET Standard and .NET Framework

* fixes build

* fixes build

* Improve async by using preprocessor

---------

Co-authored-by: Ian Cooper <[email protected]>
  • Loading branch information
lillo42 and iancooper authored Feb 14, 2025
1 parent 77ed3f7 commit ffd0f89
Show file tree
Hide file tree
Showing 53 changed files with 345 additions and 221 deletions.
8 changes: 8 additions & 0 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,16 @@
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="9.0.0-preview.2.efcore.9.0.0" />
<PackageVersion Include="Npgsql" Version="9.0.2" />
</ItemGroup>

<ItemGroup>
<GlobalPackageReference Include="MinVer" Version="6.0.0" />
<GlobalPackageReference Include="Microsoft.SourceLink.GitHub" Version="8.0.0" />
</ItemGroup>

<ItemGroup Condition="'$(TargetFramework)' == 'net462'">
<GlobalPackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</GlobalPackageReference>
</ItemGroup>
</Project>
5 changes: 5 additions & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
<FileVersion>10.0.0.0</FileVersion>
<InformationalVersion>10.0.0</InformationalVersion>
<Version>10.0.0</Version>

<!-- The .NET Version used in all projects -->
<BrigtherTargetFrameworks>netstandard2.0;net8.0;net9.0</BrigtherTargetFrameworks>
<BrigtherFrameworkAndCoreTargetFrameworks>net462;net8.0;net9.0</BrigtherFrameworkAndCoreTargetFrameworks>
<BrigtherCoreTargetFrameworks>net8.0;net9.0</BrigtherCoreTargetFrameworks>
</PropertyGroup>

<!-- Deterministic builds ensure that the same binary is produced regardless of the machine building it -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Paramore.Brighter.Storage.Azure</RootNamespace>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>$(BrigtherTargetFrameworks)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>Paramore.Brighter.Storage.Azure</RootNamespace>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs"/>
</ItemGroup>

</Project>
12 changes: 6 additions & 6 deletions src/Paramore.Brighter.Dapper/Paramore.Brighter.Dapper.csproj
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>$(BrigtherTargetFrameworks)</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj"/>
</ItemGroup>

</Project>
22 changes: 11 additions & 11 deletions src/Paramore.Brighter.DynamoDb/Paramore.Brighter.DynamoDb.csproj
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>$(BrigtherTargetFrameworks)</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="AWSSDK.DynamoDBv2" />
<PackageReference Include="NJsonSchema" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="AWSSDK.DynamoDBv2"/>
<PackageReference Include="NJsonSchema"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>$(BrigtherTargetFrameworks)</TargetFrameworks>
<Authors>Daniel Stockhammer, Toby Henderson</Authors>
<Description>Brighter Microsoft.Extensions.DependencyInjection support</Description>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" />
<PackageReference Include="System.Text.Json" />


<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions"/>
<PackageReference Include="System.Text.Json"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Paramore.Brighter.DynamoDb\Paramore.Brighter.DynamoDb.csproj" />
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj" />
<ProjectReference Include="..\Paramore.Brighter.DynamoDb\Paramore.Brighter.DynamoDb.csproj"/>
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj"/>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>$(BrigtherTargetFrameworks)</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>$(BrigtherTargetFrameworks)</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AWSSDK.DynamoDBv2" />


<ItemGroup>
<PackageReference Include="AWSSDK.DynamoDBv2"/>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj" />
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj"/>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
<PropertyGroup>
<Description>This is an implementation of the outbox used for decoupled invocation of commands by Paramore.Brighter, using MS Sql Server</Description>
<Authors>Francesco Pighi</Authors>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>$(BrigtherFrameworkAndCoreTargetFrameworks)</TargetFrameworks>
<PackageTags>RabbitMQ;AMQP;Command;Event;Service Activator;Decoupled;Invocation;Messaging;Remote;Command Dispatcher;Command Processor;Request;Service;Task Queue;Work Queue;Retry;Circuit Breaker;Availability</PackageTags>
</PropertyGroup>

<ItemGroup>
<None Remove="DDL Scripts\MSSQL\Inbox.sql" />
<None Remove="DDL Scripts\MSSQL\Inbox.sql"/>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Paramore.Brighter.MsSql\Paramore.Brighter.MsSql.csproj" />
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Paramore.Brighter.MsSql\Paramore.Brighter.MsSql.csproj"/>
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj"/>
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<Description>This is an implementation of the outbox used for decoupled invocation of commands by Paramore.Brighter, using MySql</Description>
<Authors>Derek Comartin</Authors>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>$(BrigtherTargetFrameworks)</TargetFrameworks>
<PackageTags>MySql;Command;Event;Service Activator;Decoupled;Invocation;Messaging;Remote;Command Dispatcher;Command Processor;Request;Service;Task Queue;Work Queue;Retry;Circuit Breaker;Availability</PackageTags>
</PropertyGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<Description>This is an implementation of the inbox used for decoupled invocation of commands by Paramore.Brighter, using PostgreSql</Description>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>$(BrigtherCoreTargetFrameworks)</TargetFrameworks>
<PackageTags>MySql;Command;Event;Service Activator;Decoupled;Invocation;Messaging;Remote;Command Dispatcher;Command Processor;Request;Service;Task Queue;Work Queue;Retry;Circuit Breaker;Availability</PackageTags>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<Description>This is an implementation of the inbox used for decoupled invocation of commands by Paramore.Brighter, using Sqlite</Description>
<Authors>Ian Cooper</Authors>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>$(BrigtherTargetFrameworks)</TargetFrameworks>
<PackageTags>RabbitMQ;AMQP;Command;Event;Service Activator;Decoupled;Invocation;Messaging;Remote;Command Dispatcher;Command Processor;Request;Service;Task Queue;Work Queue;Retry;Circuit Breaker;Availability</PackageTags>
</PropertyGroup>

Expand Down
28 changes: 22 additions & 6 deletions src/Paramore.Brighter.Locking.Azure/AzureBlobLockingProvider.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#region Licence

/* The MIT License (MIT)
Copyright © 2024 Ian Cooper <[email protected]>
Expand All @@ -19,7 +20,9 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. */
#endregion

#endregion

using Azure;
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Specialized;
Expand All @@ -34,7 +37,9 @@ namespace Paramore.Brighter.Locking.Azure;
/// <param name="options"></param>
public class AzureBlobLockingProvider(AzureBlobLockingProviderOptions options) : IDistributedLock
{
private readonly BlobContainerClient _containerClient = new BlobContainerClient(options.BlobContainerUri, options.TokenCredential);
private readonly BlobContainerClient _containerClient =
new BlobContainerClient(options.BlobContainerUri, options.TokenCredential);

private readonly ILogger _logger = ApplicationLogging.CreateLogger<AzureBlobLockingProviderOptions>();

/// <summary>
Expand All @@ -50,17 +55,27 @@ public class AzureBlobLockingProvider(AzureBlobLockingProviderOptions options) :
// Write if does not exist
if (!await client.ExistsAsync(cancellationToken))
{
#if NETSTANDARD
using var emptyStream = new MemoryStream();
using var writer = new StreamWriter(emptyStream);
await writer.WriteAsync(string.Empty);
await writer.FlushAsync();
emptyStream.Position = 0;
await client.UploadAsync(emptyStream, cancellationToken: cancellationToken);
#else
await using var emptyStream = new MemoryStream();
await using var writer = new StreamWriter(emptyStream);
await writer.WriteAsync(string.Empty);
await writer.FlushAsync(cancellationToken);
emptyStream.Position = 0;
await client.UploadAsync(emptyStream, cancellationToken: cancellationToken);
#endif
}

try
{
var response = await client.GetBlobLeaseClient().AcquireAsync(options.LeaseValidity, cancellationToken: cancellationToken);
var response = await client.GetBlobLeaseClient()
.AcquireAsync(options.LeaseValidity, cancellationToken: cancellationToken);
return response.Value.LeaseId;
}
catch (RequestFailedException)
Expand All @@ -80,20 +95,21 @@ public class AzureBlobLockingProvider(AzureBlobLockingProviderOptions options) :
public async Task ReleaseLockAsync(string resource, string lockId, CancellationToken cancellationToken)
{
var client = GetBlobLeaseClientForResource(resource, lockId);
if(client == null)
if (client == null)
{
_logger.LogInformation("No lock found for {LockResourceName}", resource);
return;
}

await client.ReleaseAsync(cancellationToken: cancellationToken);
}

private BlobLeaseClient? GetBlobLeaseClientForResource(string resource, string lockId) =>
GetBlobClient(resource).GetBlobLeaseClient(lockId);

private BlobClient GetBlobClient(string resource)
{
var storageLocation = options.StorageLocationFunc.Invoke(NormaliseResourceName(resource));
var storageLocation = options.StorageLocationFunc.Invoke(NormaliseResourceName(resource));
return _containerClient.GetBlobClient(storageLocation);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Title>This is the Azure Distributed Locking Provider.</Title>
<Authors>Paul Reardon</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
<PropertyGroup>
<TargetFrameworks>$(BrigtherTargetFrameworks)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Title>This is the Azure Distributed Locking Provider.</Title>
<Authors>Paul Reardon</Authors>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Paramore.Brighter\Paramore.Brighter.csproj"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Azure.Storage.Blobs"/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net8.0;net9.0</TargetFrameworks>
<TargetFrameworks>$(BrigtherTargetFrameworks)</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Title>This is the Dynamo DB Distributed Locking Provider.</Title>
Expand Down
Loading

0 comments on commit ffd0f89

Please sign in to comment.