Skip to content

Commit

Permalink
#17 - update azure function to .net 8
Browse files Browse the repository at this point in the history
  • Loading branch information
albx committed May 24, 2024
1 parent b983631 commit e9e4118
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.3.0" OutputItemType="Analyzer" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.6.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BlazorSwaTemplate.Shared\BlazorSwaTemplate.Shared.csproj" />
<FrameworkReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http.AspNetCore" Version="1.2.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.4" />
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
Expand All @@ -26,4 +27,7 @@
<ItemGroup>
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\BlazorSwaTemplate.Shared\BlazorSwaTemplate.Shared.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
using Microsoft.Azure.Functions.Worker;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.ConfigureFunctionsWebApplication()
.ConfigureServices(services =>
{
services.AddApplicationInsightsTelemetryWorkerService();
services.ConfigureFunctionsApplicationInsights();
})
.Build();

host.Run();
Original file line number Diff line number Diff line change
@@ -1,40 +1,37 @@
using BlazorSwaTemplate.Shared;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Azure.Functions.Worker;
using Microsoft.Azure.Functions.Worker.Http;
using Microsoft.Extensions.Logging;
using System.Net;
using BlazorSwaTemplate.Shared;

namespace BlazorSwaTemplate.Api;

public class WeatherForecastFunction
{
private readonly ILogger _logger;
private readonly ILogger<WeatherForecastFunction> _logger;

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

public WeatherForecastFunction(ILoggerFactory loggerFactory)
public WeatherForecastFunction(ILogger<WeatherForecastFunction> logger)
{
_logger = loggerFactory.CreateLogger<WeatherForecastFunction>();
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
}

[Function("WeatherForecast")]
public async Task<HttpResponseData> Run([HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequestData req)
public IActionResult Run([HttpTrigger(AuthorizationLevel.Function, "get")] HttpRequest req)
{
_logger.LogInformation("C# HTTP trigger function processed a request.");

var response = req.CreateResponse(HttpStatusCode.OK);

var forecasts = Enumerable.Range(1, 5).Select(index => new WeatherForecast
{
Date = DateTime.Now.AddDays(index),
TemperatureC = Random.Shared.Next(-20, 55),
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
}).ToArray();

await response.WriteAsJsonAsync(forecasts);
return response;
return new OkObjectResult(forecasts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
},
"enableLiveMetricsFilters": true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="8.0.4" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\BlazorSwaTemplate.Shared\BlazorSwaTemplate.Shared.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,4 @@ else
{
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("sample-data/weather.json");
}

public class WeatherForecast
{
public DateOnly Date { get; set; }

public int TemperatureC { get; set; }

public string? Summary { get; set; }

public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@
@using Microsoft.JSInterop
@using BlazorSwaTemplate.Client
@using BlazorSwaTemplate.Client.Layout
@using BlazorSwaTemplate.Shared

0 comments on commit e9e4118

Please sign in to comment.