Skip to content

Commit

Permalink
(#263) Upgrade .Net 9
Browse files Browse the repository at this point in the history
  • Loading branch information
phongnguyend committed Jan 17, 2025
1 parent e2d4d87 commit f577d77
Show file tree
Hide file tree
Showing 74 changed files with 423 additions and 485 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/.net-build-microservices.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 8.0.100
dotnet-version: 9.0.102

- name: Build
run: dotnet build --configuration Release
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/.net-build-monolith.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: Setup .NET Core
uses: actions/setup-dotnet@v1
with:
dotnet-version: 8.0.100
dotnet-version: 9.0.102


- name: Build
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.1" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>ClassifiedAds.CrossCuttingConcerns</RootNamespace>
</PropertyGroup>

Expand All @@ -10,7 +10,7 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.Text.Json" Version="8.0.0" />
<PackageReference Include="System.Text.Json" Version="9.0.1" />
</ItemGroup>

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

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="9.0.1" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.ComponentModel.Annotations" Version="5.0.0" />
<PackageReference Include="System.Text.Json" Version="8.0.0" />
</ItemGroup>

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

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<RootNamespace>ClassifiedAds.Infrastructure</RootNamespace>
</PropertyGroup>

<ItemGroup>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="AWS.Logger.SeriLog" Version="3.4.3" />
<PackageReference Include="AWSSDK.S3" Version="3.7.304.8" />
<PackageReference Include="AWSSDK.S3" Version="3.7.412.1" />
<PackageReference Include="Azure.Communication.Sms" Version="1.0.1" />
<PackageReference Include="Azure.Data.AppConfiguration" Version="1.3.0" />
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.3.0" />
<PackageReference Include="Azure.Identity" Version="1.10.4" />
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.17.1" />
<PackageReference Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.2.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.19.1" />
<PackageReference Include="Azure.Storage.Queues" Version="12.17.1" />
<PackageReference Include="Azure.Data.AppConfiguration" Version="1.5.0" />
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.3.2" />
<PackageReference Include="Azure.Identity" Version="1.13.2" />
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.18.2" />
<PackageReference Include="Azure.Monitor.OpenTelemetry.Exporter" Version="1.3.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.23.0" />
<PackageReference Include="Azure.Storage.Queues" Version="12.21.0" />
<PackageReference Include="Castle.Core" Version="5.1.1" />
<PackageReference Include="Confluent.Kafka" Version="2.3.0" />
<PackageReference Include="CryptographyHelper" Version="3.0.0" />
<PackageReference Include="CsvHelper" Version="30.0.1" />
<PackageReference Include="Dapper.StrongName" Version="2.1.24" />
<PackageReference Include="Confluent.Kafka" Version="2.8.0" />
<PackageReference Include="CryptographyHelper" Version="3.1.0" />
<PackageReference Include="CsvHelper" Version="33.0.1" />
<PackageReference Include="Dapper.StrongName" Version="2.1.35" />
<PackageReference Include="DinkToPdf" Version="1.0.8" />
<PackageReference Include="EntityFrameworkCore.SqlServer.SimpleBulks" Version="8.0.0" />
<PackageReference Include="IdentityModel" Version="6.2.0" />
<PackageReference Include="Google.Protobuf" Version="3.29.3" />
<PackageReference Include="Grpc.Net.Client" Version="2.67.0" />
<PackageReference Include="IdentityModel" Version="7.0.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="8.0.0" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="8.0.0" />
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="7.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Redis" Version="2.2.0" />
<PackageReference Include="Microsoft.Extensions.Caching.SqlServer" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="8.0.0" />
<PackageReference Include="MiniProfiler.AspNetCore.Mvc" Version="4.3.8" />
<PackageReference Include="MiniProfiler.EntityFrameworkCore" Version="4.3.8" />
<PackageReference Include="MiniProfiler.Providers.SqlServer" Version="4.3.8" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.7.0" />
<PackageReference Include="OpenTelemetry.Exporter.Zipkin" Version="1.7.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.7.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.7.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.EntityFrameworkCore" Version="1.0.0-beta.3" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.7.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Process" Version="0.5.0-beta.3" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.5.1" />
<PackageReference Include="PuppeteerSharp" Version="13.0.2" />
<PackageReference Include="Quartz" Version="3.8.0" />
<PackageReference Include="RabbitMQ.Client" Version="6.8.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="9.0.1" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="9.0.1" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Protocols.MessagePack" Version="9.0.1" />
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="8.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Caching.Redis" Version="2.3.0" />
<PackageReference Include="Microsoft.Extensions.Caching.SqlServer" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.AzureAppServices" Version="9.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.EventLog" Version="9.0.1" />
<PackageReference Include="MiniProfiler.AspNetCore.Mvc" Version="4.5.4" />
<PackageReference Include="MiniProfiler.EntityFrameworkCore" Version="4.5.4" />
<PackageReference Include="MiniProfiler.Providers.SqlServer" Version="4.5.4" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.11.0" />
<PackageReference Include="OpenTelemetry.Exporter.Zipkin" Version="1.11.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.11.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.10.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.EntityFrameworkCore" Version="1.10.0-beta.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Http" Version="1.10.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.Process" Version="1.10.0-beta.1" />
<PackageReference Include="OpenTelemetry.Instrumentation.Runtime" Version="1.10.0" />
<PackageReference Include="PuppeteerSharp" Version="20.0.5" />
<PackageReference Include="Quartz" Version="3.13.1" />
<PackageReference Include="RabbitMQ.Client" Version="7.0.0" />
<PackageReference Include="RazorLight" Version="2.3.1" />
<PackageReference Include="SendGrid" Version="9.28.1" />
<PackageReference Include="Serilog" Version="3.1.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.3.0" />
<PackageReference Include="SendGrid" Version="9.29.3" />
<PackageReference Include="Serilog" Version="4.2.0" />
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="3.0.1" />
<PackageReference Include="Serilog.Exceptions" Version="8.4.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Twilio" Version="6.15.2" />
<PackageReference Include="VaultSharp" Version="1.13.0.1" />
<PackageReference Include="Twilio" Version="7.8.2" />
<PackageReference Include="VaultSharp" Version="1.17.5.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public RabbitMQHealthCheck(RabbitMQHealthCheckOptions options)
_options = options;
}

public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
public async Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, CancellationToken cancellationToken = default)
{
try
{
Expand All @@ -26,14 +26,14 @@ public Task<HealthCheckResult> CheckHealthAsync(HealthCheckContext context, Canc
Password = _options.Password,
};

using var connection = connectionFactory.CreateConnection();
using var model = connection.CreateModel();
using var connection = await connectionFactory.CreateConnectionAsync(cancellationToken);
using var channel = await connection.CreateChannelAsync(cancellationToken: cancellationToken);

return Task.FromResult(HealthCheckResult.Healthy($"HostName: {_options.HostName}"));
return HealthCheckResult.Healthy($"HostName: {_options.HostName}");
}
catch (Exception exception)
{
return Task.FromResult(new HealthCheckResult(context.Registration.FailureStatus, null, exception));
return new HealthCheckResult(context.Registration.FailureStatus, null, exception);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,34 @@ namespace ClassifiedAds.Infrastructure.MessageBrokers.RabbitMQ;
public class RabbitMQReceiver<TConsumer, T> : IMessageReceiver<TConsumer, T>, IDisposable
{
private readonly RabbitMQReceiverOptions _options;
private readonly IConnection _connection;
private IModel _channel;
private string _queueName;
private IConnection _connection;
private IChannel _channel;

public RabbitMQReceiver(RabbitMQReceiverOptions options)
{
_options = options;

_connection = new ConnectionFactory
{
HostName = options.HostName,
UserName = options.UserName,
Password = options.Password,
AutomaticRecoveryEnabled = true,
DispatchConsumersAsync = true
}.CreateConnection();

_queueName = options.QueueName;

_connection.ConnectionShutdown += Connection_ConnectionShutdown;
}

private void Connection_ConnectionShutdown(object sender, ShutdownEventArgs e)
private Task Connection_ConnectionShutdownAsync(object sender, ShutdownEventArgs e)
{
// TODO: add log here

return Task.CompletedTask;
}

public Task ReceiveAsync(Func<T, MetaData, Task> action, CancellationToken cancellationToken = default)
public async Task ReceiveAsync(Func<T, MetaData, Task> action, CancellationToken cancellationToken = default)
{
_channel = _connection.CreateModel();
_connection = await new ConnectionFactory
{
HostName = _options.HostName,
UserName = _options.UserName,
Password = _options.Password,
AutomaticRecoveryEnabled = true,
}.CreateConnectionAsync(cancellationToken);

_connection.ConnectionShutdownAsync += Connection_ConnectionShutdownAsync;

_channel = await _connection.CreateChannelAsync(cancellationToken: cancellationToken);

if (_options.AutomaticCreateEnabled)
{
Expand Down Expand Up @@ -79,21 +77,21 @@ public Task ReceiveAsync(Func<T, MetaData, Task> action, CancellationToken cance

if (_options.DeadLetter.AutomaticCreateEnabled && !string.IsNullOrEmpty(_options.DeadLetter.QueueName))
{
_channel.QueueDeclare(_options.DeadLetter.QueueName, true, false, false, null);
_channel.QueueBind(_options.DeadLetter.QueueName, _options.DeadLetter.ExchangeName, _options.DeadLetter.RoutingKey, null);
await _channel.QueueDeclareAsync(_options.DeadLetter.QueueName, true, false, false, null, cancellationToken: cancellationToken);
await _channel.QueueBindAsync(_options.DeadLetter.QueueName, _options.DeadLetter.ExchangeName, _options.DeadLetter.RoutingKey, null, cancellationToken: cancellationToken);
}
}

arguments = arguments.Count == 0 ? null : arguments;

_channel.QueueDeclare(_options.QueueName, true, false, false, arguments);
_channel.QueueBind(_options.QueueName, _options.ExchangeName, _options.RoutingKey, null);
await _channel.QueueDeclareAsync(_options.QueueName, true, false, false, arguments, cancellationToken: cancellationToken);
await _channel.QueueBindAsync(_options.QueueName, _options.ExchangeName, _options.RoutingKey, null, cancellationToken: cancellationToken);
}

_channel.BasicQos(prefetchSize: 0, prefetchCount: 1, global: false);
await _channel.BasicQosAsync(prefetchSize: 0, prefetchCount: 1, global: false, cancellationToken: cancellationToken);

var consumer = new AsyncEventingBasicConsumer(_channel);
consumer.Received += async (model, ea) =>
consumer.ReceivedAsync += async (model, ea) =>
{
try
{
Expand Down Expand Up @@ -122,21 +120,17 @@ public Task ReceiveAsync(Func<T, MetaData, Task> action, CancellationToken cance

await action(message.Data, message.MetaData);

_channel.BasicAck(deliveryTag: ea.DeliveryTag, multiple: false);
await _channel.BasicAckAsync(deliveryTag: ea.DeliveryTag, multiple: false);
}
catch (Exception ex)
{
// TODO: log here
await Task.Delay(1000);
_channel.BasicNack(deliveryTag: ea.DeliveryTag, multiple: false, requeue: _options.RequeueOnFailure);
await _channel.BasicNackAsync(deliveryTag: ea.DeliveryTag, multiple: false, requeue: _options.RequeueOnFailure);
}
};

_channel.BasicConsume(queue: _queueName,
autoAck: false,
consumer: consumer);

return Task.CompletedTask;
await _channel.BasicConsumeAsync(queue: _options.QueueName, autoAck: false, consumer: consumer, cancellationToken: cancellationToken);
}

public void Dispose()
Expand Down
Loading

0 comments on commit f577d77

Please sign in to comment.