Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration from .NET 7.0 to .NET 8.0 #272

Merged
merged 12 commits into from
Jan 4, 2025
Merged
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 .azure/azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ steps:
displayName: 'docker compose -f ./docker-compose/docker-compose.tests.yml up -d'

- task: UseDotNet@2
displayName: 'install .net sdk 7.x'
displayName: 'install .net sdk 8.x'
inputs:
version: 7.x
version: 8.x
installationPath: $(Agent.ToolsDirectory)/dotnet

- script: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x

- name: docker compose -f ./docker-compose/docker-compose.tests.yml up -d
run: docker compose -f ./docker-compose/docker-compose.tests.yml up -d
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_test_and_publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 7.0.x
dotnet-version: 8.0.x

- name: Setup NuGet
uses: nuget/setup-nuget@v1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand All @@ -27,7 +27,7 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="MailKit" Version="4.5.0" />
<PackageReference Include="MailKit" Version="4.9.0" />
<!-- Insert additional references above this line -->
</ItemGroup>

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

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<Nullable>enable</Nullable>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Newtonsoft.Json;
using OnlineSales.Configuration;
using OnlineSales.Entities;
using OnlineSales.Helpers;
using OnlineSales.Infrastructure;
Expand Down Expand Up @@ -148,7 +149,8 @@ private async Task<ActionResult> AddEvents<T>(List<T> records)
try
{
// lock is required here because if two webhook events or imports start at the same time and try to create new contacts - one may fail later due too dupliacate email error
using (LockManager.GetWaitLock("SendGridAddEventsWaitLock", dbContext.Database.GetConnectionString()!))
var postgresConfig = dbContext.Configuration.GetSection("Postgres").Get<PostgresConfig>()!;
using (LockManager.GetWaitLock("SendGridAddEventsWaitLock", postgresConfig.ConnectionString))
{
var emailRecords = records.GroupBy(r => r.Email);

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

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
8 changes: 0 additions & 8 deletions plugins/OnlineSales.Plugin.Sms/Exceptions/AwsSnsException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
// Licensed under the MIT license. See LICENSE file in the samples root for full license information.
// </copyright>

using System.Runtime.Serialization;

namespace OnlineSales.Plugin.Sms.Exceptions
{
[Serializable]
public class AwsSnsException : Exception
{
public AwsSnsException()
Expand All @@ -22,10 +19,5 @@ public AwsSnsException(string? message, Exception? innerException)
: base(message, innerException)
{
}

protected AwsSnsException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
// Licensed under the MIT license. See LICENSE file in the samples root for full license information.
// </copyright>

using System.Runtime.Serialization;

namespace OnlineSales.Plugin.Sms.Exceptions;

[Serializable]
public class GetshoutoutException : Exception
{
public GetshoutoutException()
Expand All @@ -22,9 +19,4 @@ public GetshoutoutException(string? message, Exception? innerException)
: base(message, innerException)
{
}

protected GetshoutoutException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
// Licensed under the MIT license. See LICENSE file in the samples root for full license information.
// </copyright>

using System.Runtime.Serialization;

namespace OnlineSales.Plugin.Sms.Exceptions
{
[Serializable]
public class NotifyLkException : Exception
{
public NotifyLkException()
Expand All @@ -22,10 +19,5 @@ public NotifyLkException(string? message, Exception? innerException)
: base(message, innerException)
{
}

protected NotifyLkException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
// Licensed under the MIT license. See LICENSE file in the samples root for full license information.
// </copyright>

using System.Runtime.Serialization;

namespace OnlineSales.Plugin.Sms.Exceptions
{
[Serializable]
public class SmsPluginException : Exception
{
public SmsPluginException()
Expand All @@ -22,10 +19,5 @@ public SmsPluginException(string? message, Exception? innerException)
: base(message, innerException)
{
}

protected SmsPluginException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
8 changes: 0 additions & 8 deletions plugins/OnlineSales.Plugin.Sms/Exceptions/SmscException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
// Licensed under the MIT license. See LICENSE file in the samples root for full license information.
// </copyright>

using System.Runtime.Serialization;

namespace OnlineSales.Plugin.Sms.Exceptions
{
[Serializable]
public class SmscException : Exception
{
public SmscException()
Expand All @@ -22,10 +19,5 @@ public SmscException(string? message, Exception? innerException)
: base(message, innerException)
{
}

protected SmscException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
8 changes: 0 additions & 8 deletions plugins/OnlineSales.Plugin.Sms/Exceptions/TwilioException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
// Licensed under the MIT license. See LICENSE file in the samples root for full license information.
// </copyright>

using System.Runtime.Serialization;

namespace OnlineSales.Plugin.Sms.Exceptions
{
[Serializable]
public class TwilioException : Exception
{
public TwilioException()
Expand All @@ -22,10 +19,5 @@ public TwilioException(string? message, Exception? innerException)
: base(message, innerException)
{
}

protected TwilioException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@
// Licensed under the MIT license. See LICENSE file in the samples root for full license information.
// </copyright>

using System.Runtime.Serialization;

namespace OnlineSales.Plugin.Sms.Exceptions
{
[Serializable]
public class UnknownCountryCodeException : Exception
{
public UnknownCountryCodeException()
Expand All @@ -22,10 +19,5 @@ public UnknownCountryCodeException(string? message, Exception? innerException)
: base(message, innerException)
{
}

protected UnknownCountryCodeException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
Expand Down
4 changes: 2 additions & 2 deletions src/OnlineSales/Controllers/ActivityLogController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public virtual async Task<ActionResult<List<ActivityLogDetailsDto>>> Get([FromQu
var qp = queryProviderFactory.BuildQueryProvider();

var result = await qp.GetResult();
Response.Headers.Add(ResponseHeaderNames.TotalCount, result.TotalCount.ToString());
Response.Headers.Add(ResponseHeaderNames.AccessControlExposeHeader, ResponseHeaderNames.TotalCount);
Response.Headers.Append(ResponseHeaderNames.TotalCount, result.TotalCount.ToString());
Response.Headers.Append(ResponseHeaderNames.AccessControlExposeHeader, ResponseHeaderNames.TotalCount);
return Ok(mapper.Map<List<ActivityLogDetailsDto>>(result.Records));
}
}
8 changes: 4 additions & 4 deletions src/OnlineSales/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,8 @@ public virtual async Task<ActionResult<List<TD>>> Get([FromQuery] string? query)
var qp = queryProviderFactory.BuildQueryProvider();

var result = await qp.GetResult();
Response.Headers.Add(ResponseHeaderNames.TotalCount, result.TotalCount.ToString());
Response.Headers.Add(ResponseHeaderNames.AccessControlExposeHeader, ResponseHeaderNames.TotalCount);
Response.Headers.Append(ResponseHeaderNames.TotalCount, result.TotalCount.ToString());
Response.Headers.Append(ResponseHeaderNames.AccessControlExposeHeader, ResponseHeaderNames.TotalCount);
var res = mapper.Map<List<TD>>(result.Records);
RemoveSecondLevelObjects(res);
return Ok(res);
Expand All @@ -120,8 +120,8 @@ public virtual async Task<ActionResult<List<TD>>> Export([FromQuery] string? que
var qp = queryProviderFactory.BuildQueryProvider(int.MaxValue);

var result = await qp.GetResult();
Response.Headers.Add(ResponseHeaderNames.TotalCount, result.TotalCount.ToString());
Response.Headers.Add(ResponseHeaderNames.AccessControlExposeHeader, ResponseHeaderNames.TotalCount);
Response.Headers.Append(ResponseHeaderNames.TotalCount, result.TotalCount.ToString());
Response.Headers.Append(ResponseHeaderNames.AccessControlExposeHeader, ResponseHeaderNames.TotalCount);
var res = mapper.Map<List<TD>>(result.Records);
RemoveSecondLevelObjects(res);
return Ok(res);
Expand Down
4 changes: 2 additions & 2 deletions src/OnlineSales/Controllers/UsersController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public async Task<ActionResult<UserDetailsDto[]>> GetAll()
{
var allUsers = await userManager.Users.ToListAsync();
var resultsToClient = mapper.Map<UserDetailsDto[]>(allUsers).ToArray();
Response.Headers.Add(ResponseHeaderNames.TotalCount, resultsToClient.Count().ToString());
Response.Headers.Add(ResponseHeaderNames.AccessControlExposeHeader, ResponseHeaderNames.TotalCount);
Response.Headers.Append(ResponseHeaderNames.TotalCount, resultsToClient.Count().ToString());
Response.Headers.Append(ResponseHeaderNames.AccessControlExposeHeader, ResponseHeaderNames.TotalCount);
return Ok(resultsToClient);
}

Expand Down
44 changes: 44 additions & 0 deletions src/OnlineSales/Data/DataSourceSingleton.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// <copyright file="DataSourceSingleton.cs" company="WavePoint Co. Ltd.">
// Licensed under the MIT license. See LICENSE file in the samples root for full license information.
// </copyright>

using Npgsql;
using OnlineSales.Configuration;

namespace OnlineSales.Data;

public static class DataSourceSingleton
{
private static readonly object InstanceLock = new object();
private static NpgsqlDataSource? instance = null;

public static NpgsqlDataSource GetInstance(IConfiguration configuration)
{
if (instance == null)
{
lock (InstanceLock)
{
if (instance == null)
{
instance = BuildDataSource(configuration);
}
}
}

return instance;
}

private static NpgsqlDataSource BuildDataSource(IConfiguration configuration)
{
var postgresConfig = configuration.GetSection("Postgres").Get<PostgresConfig>();

if (postgresConfig == null)
{
throw new MissingConfigurationException("Postgres configuration is mandatory.");
}

var dataSourceBuilder = new NpgsqlDataSourceBuilder(postgresConfig.ConnectionString);
dataSourceBuilder.EnableDynamicJson();
return dataSourceBuilder.Build();
}
}
10 changes: 1 addition & 9 deletions src/OnlineSales/Data/PgDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.ChangeTracking;
using Microsoft.EntityFrameworkCore.Migrations;
using OnlineSales.Configuration;
using OnlineSales.DataAnnotations;
using OnlineSales.Entities;
using OnlineSales.Helpers;
Expand Down Expand Up @@ -208,15 +207,8 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
Console.WriteLine("Configuring PgDbContext...");

var postgresConfig = Configuration.GetSection("Postgres").Get<PostgresConfig>();

if (postgresConfig == null)
{
throw new MissingConfigurationException("Postgres configuration is mandatory.");
}

optionsBuilder.UseNpgsql(
postgresConfig.ConnectionString,
DataSourceSingleton.GetInstance(Configuration),
b => b.MigrationsHistoryTable("_migrations"))
.UseSnakeCaseNamingConvention()
.ReplaceService<IMigrationsSqlGenerator, CustomSqlServerMigrationsSqlGenerator>();
Expand Down
Loading
Loading