Skip to content

Commit 66dbdb5

Browse files
Migration to .NET 8 (#207)
* Migration to .NET 8 * Change port.
1 parent a5f8577 commit 66dbdb5

File tree

134 files changed

+343
-501
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+343
-501
lines changed

Dockerfile

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#
22
# Stage 1, Build Backend
33
#
4-
FROM mcr.microsoft.com/dotnet/sdk:7.0 as backend
4+
FROM mcr.microsoft.com/dotnet/sdk:8.0 as backend
55

66
ARG NOTIFO__BUILD__VERSION=1.0.0
77

@@ -65,7 +65,7 @@ RUN cp -a build /build/
6565
#
6666
# Stage 3, Build runtime
6767
#
68-
FROM mcr.microsoft.com/dotnet/aspnet:7.0-bullseye-slim
68+
FROM mcr.microsoft.com/dotnet/aspnet:8.0-bookworm-slim
6969

7070
ARG NOTIFO__RUNTIME__VERSION=1.0.0
7171

@@ -92,6 +92,7 @@ ENV DIAGNOSTICS__COUNTERSTOOL=/tools/dotnet-counters
9292
ENV DIAGNOSTICS__DUMPTOOL=/tools/dotnet-dump
9393
ENV DIAGNOSTICS__GCDUMPTOOL=/tools/dotnet-gcdump
9494
ENV DIAGNOSTICS__TRACETOOL=/tools/dotnet-trace
95+
ENV ASPNETCORE_HTTP_PORTS=80
9596

9697
ENTRYPOINT ["dotnet", "Notifo.dll"]
9798

backend/.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ dotnet_diagnostic.RECS0117.severity = none
2121
dotnet_diagnostic.SA0001.severity = none
2222
dotnet_diagnostic.SA1649.severity = none
2323

24+
# IDE0290: Use primary constructor
25+
dotnet_diagnostic.IDE0290.severity = none
26+
27+
# IDE0305: Simplify collection initialization
28+
dotnet_diagnostic.IDE0305.severity = none
29+
2430
# CA1707: Identifiers should not contain underscores
2531
dotnet_diagnostic.CA1707.severity = none
2632

@@ -99,6 +105,9 @@ dotnet_diagnostic.RECS0154.severity = none
99105
# SA1009: Closing parenthesis should be spaced correctly
100106
dotnet_diagnostic.SA1009.severity = none
101107

108+
# SA1010: Opening square brackets should not be preceded by a space.
109+
dotnet_diagnostic.SA1010.severity = none
110+
102111
# SA1011: Closing square brackets should be spaced correctly
103112
dotnet_diagnostic.SA1011.severity = none
104113

backend/src/Notifo.Domain.Integrations.Abstractions/MobilePushTokenExpiredException.cs

-7
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
// All rights reserved. Licensed under the MIT license.
66
// ==========================================================================
77

8-
using System.Runtime.Serialization;
9-
108
namespace Notifo.Domain.Integrations;
119

1210
[Serializable]
@@ -25,9 +23,4 @@ public MobilePushTokenExpiredException(string message, Exception inner)
2523
: base(message, inner)
2624
{
2725
}
28-
29-
protected MobilePushTokenExpiredException(SerializationInfo info, StreamingContext context)
30-
: base(info, context)
31-
{
32-
}
3326
}

backend/src/Notifo.Domain.Integrations.Abstractions/Notifo.Domain.Integrations.Abstractions.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<LangVersion>latest</LangVersion>
77
<NeutralLanguage>en</NeutralLanguage>
@@ -10,7 +10,7 @@
1010
</PropertyGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="Meziantou.Analyzer" Version="2.0.83">
13+
<PackageReference Include="Meziantou.Analyzer" Version="2.0.110">
1414
<PrivateAssets>all</PrivateAssets>
1515
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1616
</PackageReference>

backend/src/Notifo.Domain.Integrations/AmazonSES/IntegratedAmazonSESIntegration.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ namespace Notifo.Domain.Integrations.AmazonSES;
2121

2222
public sealed class IntegratedAmazonSESIntegration : IIntegration, IInitializable, IEmailSender
2323
{
24+
private static readonly char[] EmailSeparators = ['\n', ',', ';'];
2425
private readonly IKeyValueStore keyValueStore;
2526
private readonly SmtpIntegration emailSender;
2627
private readonly AmazonSESOptions emailOptions;
@@ -311,7 +312,7 @@ private static IEnumerable<string> GetEmailAddresses(IReadOnlyDictionary<string,
311312
yield break;
312313
}
313314

314-
var emails = additionalEmails.Split(new[] { '\n', ',', ';' }, StringSplitOptions.RemoveEmptyEntries);
315+
var emails = additionalEmails.Split(EmailSeparators, StringSplitOptions.RemoveEmptyEntries);
315316

316317
foreach (var email in emails)
317318
{

backend/src/Notifo.Domain.Integrations/Http/HttpIntegration.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public sealed partial class HttpIntegration : IIntegration
2525
{
2626
EditorLabel = Texts.Webhook_MethodLabel,
2727
EditorDescription = Texts.Webhook_MethodHints,
28-
AllowedValues = new[] { "POST", "GET", "PATCH", "PUT", "DELETE" },
28+
AllowedValues = ["POST", "GET", "PATCH", "PUT", "DELETE"],
2929
IsRequired = false,
3030
};
3131

backend/src/Notifo.Domain.Integrations/HttpIntegrationException.cs

-15
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
// All rights reserved. Licensed under the MIT license.
66
// ==========================================================================
77

8-
using System.Runtime.Serialization;
9-
108
namespace Notifo.Domain.Integrations;
119

1210
[Serializable]
@@ -22,17 +20,4 @@ public HttpIntegrationException(string message, int statusCode = 400, TResponse?
2220
HttpResponse = response;
2321
HttpStatusCode = statusCode;
2422
}
25-
26-
protected HttpIntegrationException(SerializationInfo info, StreamingContext context)
27-
: base(info, context)
28-
{
29-
HttpResponse = info.GetValue(nameof(HttpResponse), typeof(TResponse)) as TResponse;
30-
HttpStatusCode = info.GetInt32(nameof(HttpStatusCode));
31-
}
32-
33-
public override void GetObjectData(SerializationInfo info, StreamingContext context)
34-
{
35-
info.AddValue(nameof(HttpResponse), HttpResponse);
36-
info.AddValue(nameof(HttpStatusCode), HttpStatusCode);
37-
}
3823
}

backend/src/Notifo.Domain.Integrations/MessageBird/Implementation/MessageBirdClient.cs

+3-11
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,7 @@ public async Task<ConversationResponse> GetMessageAsync(string id,
3939
{
4040
var result = await httpClient.GetFromJsonAsync<ConversationResponse>($"https://conversations.messagebird.com/v1/messages/{id}", ct);
4141

42-
if (result == null)
43-
{
44-
throw new HttpIntegrationException<MessageBirdError>("Failed to deserialize response.");
45-
}
46-
47-
return result;
42+
return result ?? throw new HttpIntegrationException<MessageBirdError>("Failed to deserialize response.");
4843
}
4944
}
5045

@@ -160,12 +155,9 @@ private async Task<ConversationResponse> SendRequestAsync<T>(T request,
160155
using (var httpClient = httpClientFactory())
161156
{
162157
var response = await httpClient.PostAsJsonAsync("https://conversations.messagebird.com/v1/send", request, ct);
163-
var result = await response.Content.ReadFromJsonAsync<ConversationResponse>((JsonSerializerOptions?)null, ct);
164158

165-
if (result == null)
166-
{
167-
throw new HttpIntegrationException<MessageBirdError>("Failed to deserialize response.");
168-
}
159+
var result = await response.Content.ReadFromJsonAsync<ConversationResponse>((JsonSerializerOptions?)null, ct)
160+
?? throw new HttpIntegrationException<MessageBirdError>("Failed to deserialize response.");
169161

170162
var error = result.Errors?.FirstOrDefault() ?? result.Error;
171163

backend/src/Notifo.Domain.Integrations/MessageBird/Implementation/WhatsAppWebhookRequest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace Notifo.Domain.Integrations.MessageBird.Implementation;
1515
public sealed class WhatsAppWebhookRequest
1616
{
1717
[JsonIgnore]
18-
public Dictionary<string, string> Query { get; } = new Dictionary<string, string>();
18+
public Dictionary<string, string> Query { get; } = [];
1919

2020
[JsonPropertyName("type")]
2121
public string Type { get; set; }

backend/src/Notifo.Domain.Integrations/MessageBird/MessageBirdWhatsAppIntegration.Messaging.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public async Task<DeliveryResult> SendAsync(IntegrationContext context, Messagin
4646
templateName,
4747
message.UserLanguage,
4848
context.WebhookUrl.AppendQueries("reference", message.TrackingToken),
49-
new[] { message.Text });
49+
[message.Text]);
5050

5151
var client = GetClient(context);
5252

backend/src/Notifo.Domain.Integrations/MessageBird/PhoneNumberHelper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Notifo.Domain.Integrations.MessageBird;
99

1010
public static class PhoneNumberHelper
1111
{
12-
private static readonly char[] TrimChars = { ' ', '+', '0' };
12+
private static readonly char[] TrimChars = [' ', '+', '0'];
1313

1414
public static string Trim(string input)
1515
{

backend/src/Notifo.Domain.Integrations/Notifo.Domain.Integrations.csproj

+15-15
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
4+
<TargetFramework>net8.0</TargetFramework>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<LangVersion>latest</LangVersion>
77
<NeutralLanguage>en</NeutralLanguage>
88
<Nullable>enable</Nullable>
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="AWSSDK.SimpleEmail" Version="3.7.200.32" />
13-
<PackageReference Include="Confluent.Kafka" Version="2.2.0" />
12+
<PackageReference Include="AWSSDK.SimpleEmail" Version="3.7.300.3" />
13+
<PackageReference Include="Confluent.Kafka" Version="2.3.0" />
1414
<PackageReference Include="FirebaseAdmin" Version="2.4.0" />
15-
<PackageReference Include="FluentValidation" Version="11.7.1" />
16-
<PackageReference Include="Fluid.Core" Version="2.4.0" />
17-
<PackageReference Include="HtmlAgilityPack" Version="1.11.52" />
18-
<PackageReference Include="libphonenumber-csharp" Version="8.13.19" />
15+
<PackageReference Include="FluentValidation" Version="11.8.0" />
16+
<PackageReference Include="Fluid.Core" Version="2.5.0" />
17+
<PackageReference Include="HtmlAgilityPack" Version="1.11.54" />
18+
<PackageReference Include="libphonenumber-csharp" Version="8.13.24" />
1919
<PackageReference Include="Mailjet.Api" Version="3.0.0" />
20-
<PackageReference Include="MailKit" Version="4.2.0" />
21-
<PackageReference Include="Meziantou.Analyzer" Version="2.0.83">
20+
<PackageReference Include="MailKit" Version="4.3.0" />
21+
<PackageReference Include="Meziantou.Analyzer" Version="2.0.110">
2222
<PrivateAssets>all</PrivateAssets>
2323
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2424
</PackageReference>
25-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
26-
<PackageReference Include="Microsoft.Extensions.Http" Version="7.0.0" />
27-
<PackageReference Include="Microsoft.Extensions.Options" Version="7.0.1" />
28-
<PackageReference Include="MongoDB.Driver" Version="2.21.0" />
25+
<PackageReference Include="Microsoft.Extensions.Hosting" Version="8.0.0" />
26+
<PackageReference Include="Microsoft.Extensions.Http" Version="8.0.0" />
27+
<PackageReference Include="Microsoft.Extensions.Options" Version="8.0.0" />
28+
<PackageReference Include="MongoDB.Driver" Version="2.22.0" />
2929
<PackageReference Include="NodaTime" Version="3.1.9" />
3030
<PackageReference Include="OpenNotifications" Version="0.3.0" />
3131
<PackageReference Include="RefactoringEssentials" Version="5.6.0" PrivateAssets="all" />
3232
<PackageReference Include="System.Collections" Version="4.3.0" />
33-
<PackageReference Include="System.Net.Http.Json" Version="7.0.1" />
33+
<PackageReference Include="System.Net.Http.Json" Version="8.0.0" />
3434
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" />
3535
<PackageReference Include="Telegram.Bot" Version="19.0.0" />
36-
<PackageReference Include="Twilio" Version="6.11.0" />
36+
<PackageReference Include="Twilio" Version="6.15.0" />
3737
</ItemGroup>
3838

3939
<ItemGroup>

backend/src/Notifo.Domain.Integrations/OpenNotifications/OpenNotificationsExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public static DomainException ToDomainException(this OpenNotificationsException
8989

9090
static string[] GetPropertyNames(ErrorDto x)
9191
{
92-
return x.Field != null ? new[] { x.Field } : Array.Empty<string>();
92+
return x.Field != null ? new[] { x.Field } : [];
9393
}
9494
}
9595
}

backend/src/Notifo.Domain.Integrations/OpenNotifications/OpenNotificationsIntegrationBase.cs

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// All rights reserved. Licensed under the MIT license.
66
// ==========================================================================
77

8-
using Confluent.Kafka;
98
using Notifo.Infrastructure;
109
using OpenNotifications;
1110

backend/src/Notifo.Domain.Integrations/OpenNotifications/OpenNotificationsRegistry.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@ namespace Notifo.Domain.Integrations.OpenNotifications;
1515

1616
public sealed class OpenNotificationsRegistry : IIntegrationRegistry, IBackgroundProcess
1717
{
18-
private static readonly HashSet<string> ProvidersToIgnore = new HashSet<string>
19-
{
18+
private static readonly HashSet<string> ProvidersToIgnore =
19+
[
2020
"aws-email",
2121
"mailjet",
2222
"mailjet-smtp",
2323
"messagebird-sms",
2424
"smtp",
2525
"twilio-sms",
26-
};
26+
];
2727

2828
private readonly IEnumerable<IOpenNotificationsClient> clients;
2929
private readonly ILogger<OpenNotificationsRegistry> log;
30-
private Dictionary<string, IIntegration> integrations = new Dictionary<string, IIntegration>();
30+
private Dictionary<string, IIntegration> integrations = [];
3131
private CompletionTimer timer;
3232

3333
public IEnumerable<IIntegration> Integrations => integrations.Values;

backend/src/Notifo.Domain/Apps/App.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,5 @@ public sealed record App(string Id, Instant Created)
3434

3535
public ReadonlyDictionary<string, ConfiguredIntegration> Integrations { get; init; } = ReadonlyDictionary.Empty<string, ConfiguredIntegration>();
3636

37-
public CounterMap? Counters { get; init; } = new CounterMap();
37+
public CounterMap? Counters { get; init; } = [];
3838
}

backend/src/Notifo.Domain/ChannelSetting.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public void OverrideBy(ChannelSetting? source)
6262

6363
if (source.Properties?.Count > 0)
6464
{
65-
Properties ??= new NotificationProperties();
65+
Properties ??= [];
6666

6767
foreach (var (key, value) in source.Properties)
6868
{

backend/src/Notifo.Domain/Channels/Email/EmailChannel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ private async Task<DeliveryResult> SendCoreAsync(string appId, EmailMessage mess
209209

210210
if (errors?.Count > 0 || message == null)
211211
{
212-
errors ??= new List<EmailFormattingError>();
212+
errors ??= [];
213213

214214
if (errors.Count == 0)
215215
{

backend/src/Notifo.Domain/Channels/Email/EmailFormattingException.cs

-12
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
// All rights reserved. Licensed under the MIT license.
66
// ==========================================================================
77

8-
using System.Runtime.Serialization;
98
using System.Text;
109

1110
namespace Notifo.Domain.Channels.Email;
@@ -21,17 +20,6 @@ public EmailFormattingException(IEnumerable<EmailFormattingError> errors)
2120
Errors = errors.ToList();
2221
}
2322

24-
protected EmailFormattingException(SerializationInfo info, StreamingContext context)
25-
: base(info, context)
26-
{
27-
Errors = info.GetValue(nameof(Errors), typeof(List<EmailFormattingError>)) as List<EmailFormattingError> ?? new List<EmailFormattingError>();
28-
}
29-
30-
public override void GetObjectData(SerializationInfo info, StreamingContext context)
31-
{
32-
info.AddValue(nameof(Errors), Errors.ToList());
33-
}
34-
3523
private static string BuildErrorMessage(IEnumerable<EmailFormattingError> errors)
3624
{
3725
var sb = new StringBuilder();

backend/src/Notifo.Domain/Channels/Email/Formatting/EmailContext.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal sealed class EmailContext
2121

2222
public LiquidContext Liquid { get; private init; }
2323

24-
public List<EmailFormattingError> Errors { get; } = new List<EmailFormattingError>();
24+
public List<EmailFormattingError> Errors { get; } = [];
2525

2626
public List<EmailJob> Jobs { get; private init; }
2727

backend/src/Notifo.Domain/Channels/Email/Formatting/MjmlRenderer.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
using Notifo.Domain.Resources;
1111
using Notifo.Domain.Utils;
1212
using Notifo.Infrastructure;
13+
using MjmlInternalRenderer = Mjml.Net.MjmlRenderer;
1314

1415
namespace Notifo.Domain.Channels.Email.Formatting;
1516

@@ -25,7 +26,7 @@ internal static class MjmlRenderer
2526
Validator = StrictValidator.Instance,
2627
};
2728

28-
private static readonly IMjmlRenderer Renderer = new Mjml.Net.MjmlRenderer();
29+
private static readonly MjmlInternalRenderer Renderer = new MjmlInternalRenderer();
2930

3031
public static (string? Html, List<TemplateError>? Errors) Render(string? mjml, bool strict)
3132
{

backend/src/Notifo.Domain/Channels/Email/Formatting/MjmlSchema.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ namespace Notifo.Domain.Channels.Email.Formatting;
1818
public sealed class MjmlSchema
1919
{
2020
[JsonPropertyName("!top")]
21-
public List<string> Top { get; } = new List<string>();
21+
public List<string> Top { get; } = [];
2222

2323
[JsonIgnore]
24-
public Dictionary<string, MjmlSchemaElement> Elements { get; } = new Dictionary<string, MjmlSchemaElement>();
24+
public Dictionary<string, MjmlSchemaElement> Elements { get; } = [];
2525

2626
[JsonExtensionData]
2727
public Dictionary<string, object> ExtraData
@@ -79,7 +79,7 @@ public static MjmlSchema Build(IMjmlRenderer renderer)
7979
public sealed class MjmlSchemaElement
8080
{
8181
[JsonPropertyName("attrs")]
82-
public Dictionary<string, List<string>?> Attributes { get; } = new Dictionary<string, List<string>?>();
82+
public Dictionary<string, List<string>?> Attributes { get; } = [];
8383

8484
[JsonPropertyName("children")]
8585
public List<string>? Children { get; set; }

0 commit comments

Comments
 (0)