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

Upgrade to dotnet 6 and modernisation #9

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions example/Api/Api.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="3.0.7" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Shared\Shared.csproj" />
Expand Down
37 changes: 18 additions & 19 deletions example/Api/Weather.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,27 @@
using System.Linq;
using Shared;

namespace Api
namespace Api;

public static class Weather
{
public static class Weather
private static readonly string[] Summaries = new[]
{
private static readonly string[] Summaries = new[]
{
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
};

[FunctionName(nameof(Weather))]
public static IActionResult Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
[FunctionName(nameof(Weather))]
public static IActionResult Run(
[HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
var rng = new Random();
return new OkObjectResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
var rng = new Random();
return new OkObjectResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray());
}
Date = DateTime.Now.AddDays(index),
TemperatureC = rng.Next(-20, 55),
Summary = Summaries[rng.Next(Summaries.Length)]
})
.ToArray());
}
}
2 changes: 1 addition & 1 deletion example/Client/App.razor
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
@if (!context.User.Identity.IsAuthenticated)
@if (context.User.Identity?.IsAuthenticated != true)
{
<RedirectToLogin />
}
Expand Down
14 changes: 7 additions & 7 deletions example/Client/Client.csproj
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">

<PropertyGroup>
<TargetFramework>netstandard2.1</TargetFramework>
<RazorLangVersion>3.0</RazorLangVersion>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="3.2.1" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="3.2.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="3.2.1" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="3.2.0" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.10" />
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.10" PrivateAssets="all" />
<PackageReference Include="System.Net.Http.Json" Version="6.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions example/Client/Pages/Authentication.razor
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
</AppServiceAuthRemoteAuthenticatorView>

@code {
[Parameter] public string Action { get; set; }
[Parameter] public string Action { get; set; } = "";

[Parameter] public string State { get; set; } = "";

private string _selectedOption;
private string? _selectedOption;

public void SelectOption(string option) => _selectedOption = option;
}
20 changes: 11 additions & 9 deletions example/Client/Pages/FetchData.razor
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,23 @@ else
</tr>
</thead>
<tbody>
@foreach (var forecast in forecasts)
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
</tr>
@if (forecasts is not null) {
@foreach (var forecast in forecasts)
{
<tr>
<td>@forecast.Date.ToShortDateString()</td>
<td>@forecast.TemperatureC</td>
<td>@forecast.TemperatureF</td>
<td>@forecast.Summary</td>
</tr>
}
}
</tbody>
</table>
}

@code {
private WeatherForecast[] forecasts;
private WeatherForecast[]? forecasts;

protected override async Task OnInitializedAsync()
{
Expand Down
28 changes: 9 additions & 19 deletions example/Client/Program.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
using System;
using System.Net.Http;
using System.Threading.Tasks;
using Client;
using Microsoft.AspNetCore.Components.Web;
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
using Microsoft.Azure.AppService.Authentication.WebAssembly;
using Microsoft.Extensions.DependencyInjection;

namespace Client
{
public class Program
{
public static async Task Main(string[] args)
{
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
var builder = WebAssemblyHostBuilder.CreateDefault(args);
builder.RootComponents.Add<App>("app");
builder.RootComponents.Add<HeadOutlet>("head::after");

var baseAddress = builder.Configuration["ApiHost"] ?? builder.HostEnvironment.BaseAddress;
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(baseAddress) });
var baseAddress = builder.Configuration["ApiHost"] ?? builder.HostEnvironment.BaseAddress;
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(baseAddress) });

builder.Services.AddStaticWebAppsAuthentication();
builder.Services.AddStaticWebAppsAuthentication();

await builder.Build().RunAsync();
}
}
}
await builder.Build().RunAsync();
2 changes: 1 addition & 1 deletion example/Client/Shared/LoginDisplay.razor
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<AuthorizeView>
<Authorized>
Hello, @context.User.Identity.Name!
Hello, @context.User.Identity?.Name!
<button class="nav-link btn btn-link" @onclick="BeginSignOut">Log out</button>
</Authorized>
<NotAuthorized>
Expand Down
2 changes: 1 addition & 1 deletion example/Client/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@code {
private bool collapseNavMenu = true;

private string NavMenuCssClass => collapseNavMenu ? "collapse" : null;
private string? NavMenuCssClass => collapseNavMenu ? "collapse" : null;

private void ToggleNavMenu()
{
Expand Down
2 changes: 1 addition & 1 deletion example/Client/Shared/SurveyPrompt.razor
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
@code {
// Demonstrates how a parent component can supply parameters
[Parameter]
public string Title { get; set; }
public string Title { get; set; } = "";
}
3 changes: 2 additions & 1 deletion example/Client/_Imports.razor
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
@using System.Net.Http
@using System.Net.Http.Json
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.AspNetCore.Components.Web.Virtualization
@using Microsoft.AspNetCore.Components.WebAssembly.Http
@using Microsoft.AspNetCore.Authorization
@using Microsoft.JSInterop
@using Client
@using Client.Shared
Expand Down
3 changes: 1 addition & 2 deletions example/Client/wwwroot/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
{
"ApiHost": "http://localhost:70701"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"routes": [
{
"route": "/api/*",
"allowedRoles": [ "authenticated" ]
"allowedRoles": ["authenticated"]
}
]
}
2 changes: 1 addition & 1 deletion example/Shared/Shared.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

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

</Project>
6 changes: 6 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "6.0.402",
"rollForward": "latestMinor"
}
}
Loading