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

chore: Update to net7.0 #598

Merged
merged 7 commits into from
Oct 24, 2023
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
2 changes: 1 addition & 1 deletion .github/workflows/test-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 6.0.x
dotnet-version: 7.0.x
- name: Restore dependencies
run: dotnet restore
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion src/backend/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"isRoot": true,
"tools": {
"dotnet-ef": {
"version": "5.0.2",
"version": "7.0.12",
"commands": [
"dotnet-ef"
]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

Expand Down
4 changes: 2 additions & 2 deletions src/backend/api/Fusion.Resources.Api/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.

FROM mcr.microsoft.com/dotnet/aspnet:6.0-bullseye-slim AS base
FROM mcr.microsoft.com/dotnet/aspnet:7.0-bullseye-slim AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0-bullseye-slim AS build
FROM mcr.microsoft.com/dotnet/sdk:7.0-bullseye-slim AS build
WORKDIR /src
COPY ["api/Fusion.Resources.Api/Fusion.Resources.Api.csproj", "api/Fusion.Resources.Api/"]
COPY ["api/Fusion.Resources.Database/Fusion.Resources.Database.csproj", "api/Fusion.Resources.Database/"]
Expand Down
10 changes: 5 additions & 5 deletions src/backend/api/Fusion.Resources.Api/Fusion.Resources.Api.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<UserSecretsId>474454c7-2021-4f46-bfd4-02b221fc3fa0</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<DockerfileContext>..\..</DockerfileContext>
Expand All @@ -15,6 +15,7 @@
<EmbeddedResource Include="Data\personnel-import-template.xlsx" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.2.2" />
<PackageReference Include="Bogus" Version="34.0.2" />
<PackageReference Include="Fusion.Infrastructure.MediatR" Version="7.0.0" />
<PackageReference Include="Fusion.Integration" Version="7.0.4" />
Expand All @@ -29,15 +30,14 @@
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageReference Include="JSM.FluentValidation.AspNet.AsyncFilter" Version="2.0.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="6.0.13" />
<PackageReference Include="Microsoft.Extensions.Configuration.AzureKeyVault" Version="3.1.24" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.12" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.19.5" />
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="7.0.11" />
<PackageReference Include="swashbuckle.AspNetCore.Swagger" Version="6.5.0" />
<PackageReference Include="swashbuckle.AspNetCore.SwaggerGen" Version="6.5.0" />
<PackageReference Include="swashbuckle.AspNetCore.SwaggerUi" Version="6.5.0" />
<PackageReference Include=" Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="6.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.13">
<PackageReference Include=" Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="7.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.12">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
5 changes: 4 additions & 1 deletion src/backend/api/Fusion.Resources.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Azure.Identity;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
Expand Down Expand Up @@ -38,14 +39,16 @@ private static void AddKeyVault(HostBuilderContext hostBuilderContext, IConfigur
{
var tempConfig = configBuilder.Build();
var clientId = tempConfig["AzureAd:ClientId"];
var tenantId = tempConfig["AzureAd:TenantId"];
var clientSecret = tempConfig["AzureAd:ClientSecret"];
var keyVaultUrl = tempConfig["KEYVAULT_URL"];

if (!string.IsNullOrEmpty(keyVaultUrl))
{
Console.WriteLine($"Adding key vault using url: '{keyVaultUrl}', client id '{clientId}' and client secret {(string.IsNullOrEmpty(clientSecret) ? "[empty]" : "*****")}");

configBuilder.AddAzureKeyVault(keyVaultUrl, clientId, clientSecret);
var credential = new ClientSecretCredential(tenantId, clientId, clientSecret);
configBuilder.AddAzureKeyVault(new Uri(keyVaultUrl), credential);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Messaging.ServiceBus" Version="7.16.2" />
<PackageReference Include="Fusion.Integration.Profile" Version="7.0.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Azure.ServiceBus" Version="5.2.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="7.0.4" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="7.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="7.0.0" />

</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
using System;
using Microsoft.Azure.ServiceBus.Core;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using Azure.Messaging.ServiceBus;
using System.Collections.Generic;

namespace Fusion.Resources.ServiceBus
{
internal class ServiceBusQueueSender : IQueueSender
{
private readonly string connectionString;
private readonly IConfiguration configuration;
private readonly ILogger<ServiceBusQueueSender> logger;
private readonly ServiceBusClient? client;

// Caching the sender is recommended when the application is publishing messages regularly or semi-regularly. The sender is responsible for ensuring efficient network, CPU, and memory use
private Dictionary<string, ServiceBusSender> cachedSenders = new Dictionary<string, ServiceBusSender>();

public ServiceBusQueueSender(IConfiguration configuration, ILogger<ServiceBusQueueSender> logger)
{
connectionString = configuration.GetConnectionString("ServiceBus");
var connectionString = configuration.GetConnectionString("ServiceBus");

// Leaving this as nullable so integration tests etc don't fail untill the functionality is required.
if (!string.IsNullOrEmpty(connectionString))
{
this.client = new ServiceBusClient(connectionString);
}

this.configuration = configuration;
this.logger = logger;
}
Expand All @@ -30,36 +40,59 @@ public async Task SendMessageDelayedAsync(QueuePath queue, object message, int d
{
if (!IsDisabled)
{
var sender = GetClient(queue);
var jsonMessage = JsonSerializer.Serialize(message);
var queueMessage = new Microsoft.Azure.ServiceBus.Message(Encoding.UTF8.GetBytes(jsonMessage)) { ContentType = "application/json" };

var entityPath = ResolveQueuePath(queue);
var queueSender = GetQueueSender(entityPath);

var sbMessage = new ServiceBusMessage(jsonMessage) { ContentType = "application/json" };
if (delayInSeconds > 0)
{
queueMessage.ScheduledEnqueueTimeUtc = DateTime.UtcNow.AddSeconds(delayInSeconds);
}
sbMessage.ScheduledEnqueueTime = DateTime.UtcNow.AddSeconds(delayInSeconds);

logger.LogInformation($"Posting message to {sender.Path}: {jsonMessage}");
await sender.SendAsync(queueMessage);
logger.LogInformation($"Posting message to {entityPath}: {jsonMessage}");
await queueSender.SendMessageAsync(sbMessage);
}
else
{
logger.LogWarning("Sending queue messages has been disabled by config, ServiceBus:Disabled");
}
}

private MessageSender GetClient(QueuePath queue)
private ServiceBusSender GetQueueSender(string queue)
{
if (client is null)
throw new InvalidOperationException("Service bus has not been configured. Missing connection string.");

if (cachedSenders.ContainsKey(queue))
{
return cachedSenders[queue];
}

cachedSenders[queue] = client.CreateSender(queue);
return cachedSenders[queue];
}

/// <summary>
/// Queue path should be configured in config. The config key should be the enum value.
///
/// </summary>
/// <param name="queue"></param>
/// <returns></returns>
private string ResolveQueuePath(QueuePath queue)
{
var entityPath = configuration.GetValue<string>($"ServiceBus:Queues:{queue}", DefaultQueuePath(queue));
var entityPath = configuration.GetValue<string>($"ServiceBus:Queues:{queue}");


var entityPathOverride = configuration.GetValue<string>($"SERVICEBUS_QUEUES_{queue}");
if (!string.IsNullOrEmpty(entityPathOverride))
entityPath = entityPathOverride;

if (string.IsNullOrEmpty(entityPath))
entityPath = DefaultQueuePath(queue);

logger.LogInformation($"Using service bus queue: {entityPath}");

var sender = new MessageSender(connectionString, entityPath);
return sender;
return entityPath;
}

private bool IsDisabled => configuration.GetValue<bool>("ServiceBus:Disabled", false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Azure.Services.AppAuthentication" Version="1.6.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.13">
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="7.0.12">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="6.0.13" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.13" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="6.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="7.0.12" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.12" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
</ItemGroup>

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

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

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

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

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

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>

<IsPackable>false</IsPackable>
</PropertyGroup>
Expand All @@ -17,24 +17,22 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="GitHubActionsTestLogger" Version="2.3.2">
<PackageReference Include="GitHubActionsTestLogger" Version="2.3.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="FluentAssertions" Version="6.11.0" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.6.1" />
<PackageReference Include="Moq" Version="4.18.4" />
<PackageReference Include="xunit" Version="2.4.2" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PackageReference Include="Microsoft.Extensions.Configuration" Version="7.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="6.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="6.0.13" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Testing" Version="7.0.12" />

</ItemGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using Azure.Messaging.ServiceBus;
using Bogus;
using Fusion.Events;
using Microsoft.Azure.ServiceBus;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -82,16 +82,16 @@ private Task DispatchNotification<T>(FusionEventType type, FusionEventCategory c


var messageBody = JsonConvert.SerializeObject(cEvent);
var sbMessage = new Message(Encoding.UTF8.GetBytes(messageBody))
var sbMessage = new ServiceBusMessage(Encoding.UTF8.GetBytes(messageBody))
{
MessageId = $"{type.Name}-{cEvent.Id}"
};

sbMessage.UserProperties.Add("type", type.Name);
sbMessage.ApplicationProperties.Add("type", type.Name);

if (!string.IsNullOrEmpty(appContext))
{
sbMessage.UserProperties.Add("app", appContext);
sbMessage.ApplicationProperties.Add("app", appContext);
}

return bus.PublishMessageAsync(entityPath, sbMessage);
Expand Down
Loading
Loading