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

Update projects to .NET 8 #395

Merged
merged 1 commit into from
Aug 26, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public async Task<IActionResult> GetTicketImage(string imageName)
{
try
{
if (imageName.IsNullOrEmpty())
if (string.IsNullOrEmpty(imageName))
{
return BadRequest();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Relecloud.Web.CallCenter.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@

var hasRequiredConfigSettings = !string.IsNullOrEmpty(builder.Configuration["App:AppConfig:Uri"]);

if (hasRequiredConfigSettings)
if (hasRequiredConfigSettings)
{
builder.Configuration.AddAzureAppConfiguration(options =>
{
options
.Connect(new Uri(builder.Configuration["App:AppConfig:Uri"]), azureCredential)
.Connect(new Uri(builder.Configuration["App:AppConfig:Uri"]!), azureCredential)
.UseFeatureFlags() // Feature flags will be loaded and, by default, refreshed every 30 seconds
.ConfigureKeyVault(kv =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,42 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>132c573d-ea30-413d-9176-5f0fe269d568</UserSecretsId>
</PropertyGroup>
<PropertyGroup>
<IncludeOpenAPIAnalyzers>true</IncludeOpenAPIAnalyzers>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net8.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>132c573d-ea30-413d-9176-5f0fe269d568</UserSecretsId>
</PropertyGroup>
<PropertyGroup>
<IncludeOpenAPIAnalyzers>true</IncludeOpenAPIAnalyzers>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.2.1" />
<PackageReference Include="Azure.Identity" Version="1.12.0" />
<PackageReference Include="Azure.Search.Documents" Version="11.4.0-beta.5" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.13.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="5.0.12" />
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="5.0.0" />
<PackageReference Include="Microsoft.Data.SqlClient" Version="4.1.0" />
<PackageReference Include="Microsoft.Extensions.ApiDescription.Client" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="6.0.1" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.20.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.1">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="6.0.1" />
<ItemGroup>
<PackageReference Include="Azure.Extensions.AspNetCore.Configuration.Secrets" Version="1.3.2" />
<PackageReference Include="Azure.Search.Documents" Version="11.6.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.21.2" />
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="7.3.0" />
<PackageReference Include="Microsoft.Extensions.ApiDescription.Client" Version="8.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.8" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.8" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<TreatAsUsed>true</TreatAsUsed>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.8" />
<PackageReference Include="Microsoft.Azure.StackExchangeRedis" Version="3.1.0" />
<PackageReference Include="Microsoft.Identity.Web" Version="1.23.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="Polly.Contrib.WaitAndRetry" Version="1.1.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
<PackageReference Include="Microsoft.Identity.Web" Version="3.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="8.0.4" />
<PackageReference Include="Polly.Contrib.WaitAndRetry" Version="1.1.1" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.7.1" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Relecloud.Web.Models\Relecloud.Web.Models.csproj" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Relecloud.Web.Models\Relecloud.Web.Models.csproj" />
</ItemGroup>

</Project>
7 changes: 5 additions & 2 deletions src/Relecloud.Web.CallCenter.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ public void ConfigureServices(IServiceCollection services)
services.AddEndpointsApiExplorer();
services.AddSwaggerGen();

services.AddApplicationInsightsTelemetry(Configuration["App:Api:ApplicationInsights:ConnectionString"]);
services.AddApplicationInsightsTelemetry(options =>
{
options.ConnectionString = Configuration["App:Api:ApplicationInsights:ConnectionString"];
});

AddAzureSearchService(services);
AddConcertContextServices(services);
Expand Down Expand Up @@ -96,7 +99,7 @@ private void AddAzureSearchService(IServiceCollection services)
else
{
// Add a concert search service based on Azure Search.
services.AddScoped<IConcertSearchService>(x => new AzureSearchConcertSearchService(azureSearchServiceName, sqlDatabaseConnectionString));
services.AddScoped<IConcertSearchService>(x => new AzureSearchConcertSearchService(azureSearchServiceName, sqlDatabaseConnectionString!));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Relecloud.Web.CallCenter/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
builder.Configuration.AddAzureAppConfiguration(options =>
{
options
.Connect(new Uri(builder.Configuration["App:AppConfig:Uri"]), azureCredential)
.Connect(new Uri(builder.Configuration["App:AppConfig:Uri"]!), azureCredential)
.ConfigureKeyVault(kv =>
{
// Some of the values coming from Azure App Configuration are stored Key Vault, use
Expand Down
23 changes: 10 additions & 13 deletions src/Relecloud.Web.CallCenter/Relecloud.Web.CallCenter.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>ff868c0e-c82e-4217-930f-cd0391eecc21</UserSecretsId>
Expand All @@ -12,22 +12,19 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.12.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.20.0" />
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.ApiDescription.Client" Version="3.0.0">
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
<PackageReference Include="Microsoft.Azure.AppConfiguration.AspNetCore" Version="7.3.0" />
<PackageReference Include="Microsoft.Extensions.ApiDescription.Client" Version="8.0.8">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="6.0.2" />
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="8.0.8" />
<PackageReference Include="Microsoft.Azure.StackExchangeRedis" Version="3.1.0" />
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="6.0.1" />
<PackageReference Include="Microsoft.Identity.Web" Version="1.25.1" />
<PackageReference Include="Microsoft.Identity.Web.MicrosoftGraph" Version="1.25.1" />
<PackageReference Include="Microsoft.Identity.Web.UI" Version="1.22.1" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="NSwag.ApiDescription.Client" Version="13.0.5">
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="8.0.8" />
<PackageReference Include="Microsoft.Identity.Web" Version="3.1.0" />
<PackageReference Include="Microsoft.Identity.Web.DownstreamApi" Version="3.1.0" />
<PackageReference Include="Microsoft.Identity.Web.UI" Version="3.1.0" />
<PackageReference Include="NSwag.ApiDescription.Client" Version="14.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Options;
using Microsoft.AspNetCore.Authentication;
using Microsoft.Extensions.Options;
using Microsoft.Identity.Web;
using Relecloud.Web.CallCenter.Infrastructure;
using Relecloud.Web.CallCenter.Services.RelecloudApiServices;
Expand Down Expand Up @@ -223,13 +224,19 @@ public async Task<UpdateResult> UpdateConcertAsync(Concert model)

private async Task PrepareAuthenticatedClient()
{
var identity = this.httpContextAccessor.HttpContext?.User?.Identity;
if (identity != null && identity.IsAuthenticated)
{
var scopes = new[] { this.options.Value.AttendeeScope ?? throw new ArgumentNullException(nameof(this.options.Value.AttendeeScope)) };
var accessToken = await this.tokenAcquisition.GetAccessTokenForUserAsync(scopes);
this.httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
this.httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
if (this.httpContextAccessor.HttpContext is { User.Identity.IsAuthenticated: true } context)
{
try
{
var scopes = new[] { this.options.Value.AttendeeScope ?? throw new ArgumentNullException(nameof(this.options.Value.AttendeeScope)) };
var accessToken = await this.tokenAcquisition.GetAccessTokenForUserAsync(scopes);
this.httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", accessToken);
this.httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
}
catch (MicrosoftIdentityWebChallengeUserException)
{
await context.ChallengeAsync();
}
}
}
}
Expand Down
21 changes: 10 additions & 11 deletions src/Relecloud.Web.CallCenter/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ public void ConfigureServices(IServiceCollection services)
services.AddOptions();
AddMicrosoftEntraIdServices(services);
services.AddControllersWithViews();
services.AddApplicationInsightsTelemetry(Configuration["App:Api:ApplicationInsights:ConnectionString"]);
services.AddApplicationInsightsTelemetry(options =>
{
options.ConnectionString = Configuration["App:Api:ApplicationInsights:ConnectionString"];
});

AddConcertContextService(services);
AddConcertSearchService(services);
Expand Down Expand Up @@ -180,8 +183,8 @@ private void AddMicrosoftEntraIdServices(IServiceCollection services)
});

var builder = services.AddMicrosoftIdentityWebAppAuthentication(Configuration, "MicrosoftEntraId")
.EnableTokenAcquisitionToCallDownstreamApi(new string[] { })
.AddDownstreamWebApi("relecloud-api", Configuration.GetSection("GraphBeta"));
.EnableTokenAcquisitionToCallDownstreamApi(new string[] { })
.AddDownstreamApi("relecloud-api", Configuration.GetSection("GraphBeta"));

// when using Microsoft.Identity.Web to retrieve an access token on behalf of the authenticated user
// you should use a shared session state provider.
Expand Down Expand Up @@ -262,7 +265,6 @@ private static async Task CreateOrUpdateUserInformation(TokenValidatedContext ct

public void Configure(WebApplication app, IWebHostEnvironment env)
{

// Configure the HTTP request pipeline.
if (!env.IsDevelopment())
{
Expand Down Expand Up @@ -294,13 +296,10 @@ public void Configure(WebApplication app, IWebHostEnvironment env)

app.MapHealthChecks("/healthz");

app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
endpoints.MapRazorPages();
});
app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
app.MapRazorPages();
}
}
}
Loading