Skip to content

Commit

Permalink
Feature/dotnet 9 and fixes (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonkurtz-MSFT authored Nov 9, 2024
1 parent 3bee995 commit 1236432
Show file tree
Hide file tree
Showing 58 changed files with 707 additions and 212 deletions.
20 changes: 5 additions & 15 deletions SUPPORT.md
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
# TODO: The maintainer of this repo has not yet edited this file

**REPO OWNER**: Do you want Customer Service & Support (CSS) support for this product/project?

- **No CSS support:** Fill out this template with information about how to file issues and get help.
- **Yes CSS support:** Fill out an intake form at [aka.ms/onboardsupport](https://aka.ms/onboardsupport). CSS will work with/help you to determine next steps.
- **Not sure?** Fill out an intake as though the answer were "Yes". CSS will help you decide.

*Then remove this first heading from this SUPPORT.MD file before publishing your repo.*

# Support

## How to file issues and get help
## How to file issues and get help

This project uses GitHub Issues to track bugs and feature requests. Please search the existing
issues before filing new issues to avoid duplicates. For new issues, file your bug or
This project uses GitHub Issues to track bugs and feature requests. Please search the existing
issues before filing new issues to avoid duplicates. For new issues, file your bug or
feature request as a new Issue.

For help and questions about using this project, please **REPO MAINTAINER: INSERT INSTRUCTIONS HERE
For help and questions about using this project, please **REPO MAINTAINER: INSERT INSTRUCTIONS HERE
FOR HOW TO ENGAGE REPO OWNERS OR COMMUNITY FOR HELP. COULD BE A STACK OVERFLOW TAG OR OTHER
CHANNEL. WHERE WILL YOU HELP PEOPLE?**.

## Microsoft Support Policy
## Microsoft Support Policy

Support for this **PROJECT or PRODUCT** is limited to the resources listed above.
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapr.AspNetCore" Version="1.12.0" />
<PackageReference Include="Dapr.AspNetCore" Version="1.14.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.15.1" />
<PackageReference Include="SendGrid" Version="9.28.1" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapr.AspNetCore" Version="1.12.0" />
<PackageReference Include="Dapr.AspNetCore" Version="1.14.0" />
<PackageReference Include="Microsoft.Azure.Cosmos" Version="3.29.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.15.1" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapr.AspNetCore" Version="1.12.0" />
<PackageReference Include="Dapr.AspNetCore" Version="1.14.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.15.1" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.21.0" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.22.0" />
</ItemGroup>
</Project>
15 changes: 4 additions & 11 deletions docs/aca/00-workshop-intro/4-prerequisites.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
---
title: Prerequisites
title: Prerequisites
parent: Workshop Introduction
has_children: false
nav_order: 4
---

## Prerequisites

The workshop is divided into separate modules. Each module will guide you through building the solution code step-by-step. Ensure that you finish the modules in the right order as they have dependencies on each other.
The workshop is divided into separate modules. Each module will guide you through building the solution code step-by-step. Ensure that you finish the modules in the right order as they have dependencies on each other.

Make sure you have your development environment set up and configured.

1. An Azure account with an active subscription - [Create an account for free](https://azure.microsoft.com/free/?ref=microsoft.com&utm_source=microsoft.com&utm_medium=docs&utm_campaign=visualstudio){target=_blank}
1. .NET 8 or a higher version - [Install](https://dotnet.microsoft.com/en-us/download){target=_blank}
1. .NET 8 or a higher version (we primarily focus on LTS versions) - [Install](https://dotnet.microsoft.com/en-us/download){target=_blank}
1. PowerShell 7.0 or higher version (For Windows Users only!) - [Install](https://learn.microsoft.com/en-us/powershell/scripting/install/installing-powershell-on-windows?view=powershell-7.4#installing-the-msi-package){target=_blank}
1. Docker Desktop - [Install](https://docs.docker.com/desktop/install/windows-install/){target=_blank}
1. Visual Studio Code - [Install](https://code.visualstudio.com/){target=_blank}
Expand Down Expand Up @@ -81,14 +81,7 @@ This workshop typically spans several days. As such, you may close your tools, e
- Copy the [Set-Variables.ps1 script](../../aca/30-appendix/03-variables.md){target=_blank} into the newly-created `Set-Variables.ps1` file and save it.
- Perform an initial commit of the `Set-Variables.ps1` file.
```shell
git add .\Set-Variables.ps1
git commit -m "Initialize Set-Variables.ps1"
```
- Execute the script. You will do this repeatedly throughout the modules. The output of the script will inform you how many variables are written out.
- Execute the script. You will do this repeatedly throughout the modules. The output of the script will inform you how many variables are written out. As we have not yet defined any variables, the output will indicate that the script has exited. This is intentional and expected at this stage.
```shell
.\Set-Variables.ps1
Expand Down
File renamed without changes.
26 changes: 26 additions & 0 deletions docs/aca/01-deploy-api-to-aca/Program-dotnet9.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using TasksTracker.TasksManager.Backend.Api.Services;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.

builder.Services.AddSingleton<ITasksManager, FakeTasksManager>();
builder.Services.AddControllers();
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.MapOpenApi();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "8.0.100",
"version": "8.0.403",
"rollForward": "latestFeature"
}
}
6 changes: 6 additions & 0 deletions docs/aca/01-deploy-api-to-aca/global-dotnet9.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"sdk": {
"version": "9.0.100-rc.2.24474.11",
"rollForward": "latestFeature"
}
}
65 changes: 42 additions & 23 deletions docs/aca/01-deploy-api-to-aca/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,37 @@ In this module, we will accomplish three objectives:

1. Create the first microservice, `{{ apps.backend}}`, which serves as the API for our tasks.
1. Create the initial Azure infrastructure that we will need throughout this workshop.
1. Deploy the ``{{ apps.backend }}` container app to Azure.
1. Deploy the `{{ apps.backend }}` container app to Azure.

## Module Sections

### 1. Create the backend API project (Web API)

- From VS Code's *Terminal* tab, select *New Terminal* to open a (PowerShell) terminal in the project folder *TasksTracker.ContainerApps* (also referred to as *root*).
- If a terminal is not yet open, from VS Code's *Terminal* tab, select *New Terminal* to open a (PowerShell) terminal in the project folder *TasksTracker.ContainerApps* (also referred to as *root*).

- We need to define the .NET version we will use throughout this workshop. In the terminal execute `dotnet --info`. Take note of the intalled .NET SDK versions and select the one with which you wish to proceed.

- In the root folder create a new file and set the .NET SDK version from the above command:

=== "global.json"
```json hl_lines="3"
--8<-- "docs/aca/01-deploy-api-to-aca/global.json"
```
=== ".NET 8"

=== "global.json"
```json hl_lines="3"
--8<-- "docs/aca/01-deploy-api-to-aca/global-dotnet8.json"
```

=== ".NET 9"

=== "global.json"
```json hl_lines="3"
--8<-- "docs/aca/01-deploy-api-to-aca/global-dotnet9.json"
```

- Now we can initialize the backend API project. This will create and ASP.NET Web API project scaffolded with a single controller.

!!! note "Controller-Based vs. Minimal APIs"

APIs can be created via the traditional, expanded controller-based structure with _Controllers_ and _Models_ folders, etc. or via the newer minimal APIs approach where controller actions are written inside _Program.cs_. The latter approach is preferential in a microservices project where the endpoints are overseeable and may easily be represented by a more compact view.

As our workshop takes advantage of microservices, the use case for minimal APIs is given. However, in order to make the workshop a bit more demonstrable, we will, for now, stick with controller-based APIs.
APIs can be created via the traditional, expanded controller-based structure with _Controllers_ and _Models_ folders, etc. or via the newer minimal APIs approach where controller actions are written inside _Program.cs_. The latter approach is preferential in a microservices project where the endpoints are overseeable and may easily be represented by a more compact view. As our workshop takes advantage of microservices, the use case for minimal APIs is given. However, in order to make the workshop a bit more demonstrable, we will - for now - stick with controller-based APIs.

=== ".NET 8 or above"

Expand All @@ -59,7 +66,7 @@ In this module, we will accomplish three objectives:
--8<-- "docs/aca/01-deploy-api-to-aca/TaskModel.cs"
```

- In the project root create a new folder named **Services** and add the two files below. Ensure to create it as a sibling to the *Models* folder. Add the Fake Tasks Manager service. This will be the interface of Tasks Manager service. In this module we will work with data in memory. Later on, we will implement a data store.
- In the project root create a new folder named **Services** as a sibling to the *Models* folder. Add the two files below to the *Services* folder. Add the Fake Tasks Manager service as we will work with data in memory in this module. Later on, we will implement a data store.

=== "ITasksManager.cs"
```csharp
Expand All @@ -75,10 +82,19 @@ In this module, we will accomplish three objectives:

- Now we need to register `FakeTasksManager` on project startup. Open file `#!csharp Program.cs` and register the newly created service by adding the highlighted lines from below snippet. Don't forget to include the required `using` statement for the task interface and class.

=== "Program.cs"
```csharp hl_lines="1 7"
--8<-- "docs/aca/01-deploy-api-to-aca/Program.cs"
```
=== ".NET 8"

=== "Program.cs"
```csharp hl_lines="1 7"
--8<-- "docs/aca/01-deploy-api-to-aca/Program-dotnet8.cs"
```

=== ".NET 9"

=== "Program.cs"
```csharp hl_lines="1 7"
--8<-- "docs/aca/01-deploy-api-to-aca/Program-dotnet9.cs"
```

- Inside the **Controllers** folder create a new controller with the below filename. We need to create API endpoints to manage tasks.

Expand Down Expand Up @@ -118,7 +134,7 @@ We will be using Azure CLI to deploy the Web API Backend to ACA as shown in the
az extension add --upgrade --name application-insights

# Log in to Azure
az login
az login
```

- You may be able to use the queried Azure subscription ID or you may need to set it manually depending on your setup.
Expand Down Expand Up @@ -232,11 +248,14 @@ We will be using Azure CLI to deploy the Web API Backend to ACA as shown in the
--location $LOCATION `
--app $APPINSIGHTS_NAME `
--workspace $WORKSPACE_NAME

# Get Application Insights Instrumentation Key
$APPINSIGHTS_INSTRUMENTATIONKEY=($(az monitor app-insights component show `
--resource-group $RESOURCE_GROUP `
--app $APPINSIGHTS_NAME ) | ConvertFrom-Json).instrumentationKey
--app $APPINSIGHTS_NAME `
--output json) | ConvertFrom-Json).instrumentationKey

echo $APPINSIGHTS_INSTRUMENTATIONKEY
```

#### 2.4 Azure Container Infrastructure
Expand Down Expand Up @@ -270,12 +289,12 @@ We will be using Azure CLI to deploy the Web API Backend to ACA as shown in the
```

!!! note
We are not creating an `internal-only` Azure Container App Environment. This means that the static IP will be a public IP, and container apps, by default, will be publicly available on the internet.
We are not creating an `internal-only` Azure Container App Environment. This means that the static IP will be a public IP, and container apps, by default, will be publicly available on the internet.
While this is not advised in a production workload, it is suitable for the workshop to keep the architecture confined to Azure Container Apps.

??? tip "Want to learn what above command does?"
??? tip "Want to learn what the above command does?"
- It creates an ACA environment and associates it with the Log Analytics workspace created in the previous step.
- We are setting the `--dapr-instrumentation-key` value to the instrumentation key of the Application Insights instance. This will come handy when we introduce Dapr in later modules and show how the distributed tracing between microservices/container apps are captured and visualized in Application Insights.
- We are setting the `--dapr-instrumentation-key` value to the instrumentation key of the Application Insights instance. This will come handy when we introduce Dapr in later modules and show how the distributed tracing between microservices/container apps are captured and visualized in Application Insights.
> ***NOTE:***
You can set the `--dapr-instrumentation-key` after you create the ACA environment but this is not possible via the AZ CLI right now. There is an [open issue](https://github.com/microsoft/azure-container-apps/issues/293){target=_blank} which is being tracked by the product group.
Expand Down Expand Up @@ -316,7 +335,7 @@ We will be using Azure CLI to deploy the Web API Backend to ACA as shown in the
echo "https://$fqdn/api/tasks/[email protected]"
```

??? tip "Want to learn what above command does?"
??? tip "Want to learn what the above command does?"
- Ingress param is set to `external` which means that this container app (Web API) project will be accessible from the public internet. When Ingress is set to `Internal` or `External` it will be assigned a fully qualified domain name (FQDN). Important notes about IP addresses and domain names can be found [here](https://learn.microsoft.com/en-us/azure/container-apps/ingress?tabs=bash#ip-addresses-and-domain-names){target=_blank}.
- The target port param is set to 80, this is the port our Web API container listens to for incoming requests.
- We didn't specify the ACR registry username and password, `az containerapp create` command was able to look up ACR username and password and add them as a secret under the created Azure container app for future container updates.
Expand All @@ -332,11 +351,11 @@ We will be using Azure CLI to deploy the Web API Backend to ACA as shown in the
!!! success
To test the backend api service, either click on the URL output by the last command or copy the FQDN (Application URL) of the Azure container app named `tasksmanager-backend-api`, then issue a `GET` request similar to this one: `https://tasksmanager-backend-api.<your-aca-env-unique-id>.eastus.azurecontainerapps.io/api/tasks/[email protected]` and you should receive an array of the 10 tasks similar to the below image.
Note that the specific query string matters as you may otherwise get an empty result back.
Note that the specific query string matters as you may otherwise get an empty result back.

!!! tip
You can find your Azure container app application url on the [Azure portal](https://portal.azure.com){target=_blank} overview tab.
![Web API Response](../../assets/images/01-deploy-api-to-aca/Response.jpg)

--8<-- "snippets/update-variables.md"
Expand Down
File renamed without changes.
37 changes: 37 additions & 0 deletions docs/aca/02-aca-comm/Program-dotnet9.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorPages();

builder.Services.AddHttpClient("BackEndApiExternal", httpClient =>
{
var backendApiBaseUrlExternalHttp = builder.Configuration.GetValue<string>("BackendApiConfig:BaseUrlExternalHttp");

if (!string.IsNullOrEmpty(backendApiBaseUrlExternalHttp)) {
httpClient.BaseAddress = new Uri(backendApiBaseUrlExternalHttp);
} else {
throw new("BackendApiConfig:BaseUrlExternalHttp is not defined in App Settings.");
}
});

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}

app.UseHttpsRedirection();

app.UseRouting();

app.UseAuthorization();

app.MapStaticAssets();
app.MapRazorPages()
.WithStaticAssets();

app.Run();
Loading

0 comments on commit 1236432

Please sign in to comment.