Skip to content
This repository was archived by the owner on Apr 24, 2025. It is now read-only.

Commit 052b738

Browse files
committed
Add Azure resources configuration and update README for .NET Aspire integration
1 parent 7bf1530 commit 052b738

File tree

4 files changed

+66
-25
lines changed

4 files changed

+66
-25
lines changed

README.md

Lines changed: 55 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
- Run solution
1414
- [Run locally](#run-locally)
1515
- [Run the solution](#run-the-solution)
16+
- [.NET Aspire Azure Resources creation](#net-aspire-azure-resources-creation)
1617
- [Local dev using an existing model](#local-development-using-an-existing-gpt-4o-model)
1718
- [Telemetry with .NET Aspire and Azure Application Insights](#telemetry-with-net-aspire-and-azure-application-insights)
1819
- [Resources](#resources)
@@ -112,16 +113,57 @@ Follow these steps to run the project, locally or in CodeSpaces:
112113

113114
- Navigate to the Aspire Host folder project using the command:
114115

115-
```bash
116-
cd ./src/eShopAppHost/
117-
```
116+
```bash
117+
cd ./src/eShopAppHost/
118+
```
119+
120+
- If you are running the project in Codespaces, you need to run this command:
121+
122+
```bash
123+
dotnet dev-certs https --trust
124+
```
125+
126+
- By default the AppHost project creates the necessary resources on Azure. Check the **[.NET Aspire Azure Resources creation](#net-aspire-azure-resources-creation)** section to learn how to configure the project to create Azure resources.
118127

119128
- Run the project:
120129

121-
```bash
122-
dotnet run
130+
```bash
131+
dotnet run
132+
````
133+
134+
## .NET Aspire Azure Resources creation
135+
136+
When utilizing Azure resources in your local development environment, you need to:
137+
138+
- Authenticate to the Azure Tenant where the resources will be created. Run the following command to connect with your Azure tenant:
139+
140+
```bash
141+
az login
142+
```
143+
- Provide the necessary Configuration values are specified under the Azure section in the `eShopAppHost` project:
144+
145+
- CredentialSource: Delegates to the [AzureCliCredential](https://learn.microsoft.com/dotnet/api/azure.identity.azureclicredential).
146+
- SubscriptionId: The Azure subscription ID.
147+
- AllowResourceGroupCreation: A boolean value that indicates whether to create a new resource group.
148+
- ResourceGroup: The name of the resource group to use.
149+
- Location: The Azure region to use.
150+
151+
Consider the following example for the *appsettings.json* file in the eShopAppHost project configuration:
152+
153+
```json
154+
{
155+
"Azure": {
156+
"CredentialSource": "AzureCli",
157+
"SubscriptionId": "<Your subscription id>",
158+
"AllowResourceGroupCreation": true,
159+
"ResourceGroup": "<Valid resource group name>",
160+
"Location": "<Valid Azure location>"
161+
}
162+
}
123163
```
124164
165+
Check [.NET Aspire Azure hosting integrations](https://learn.microsoft.com/en-us/dotnet/aspire/azure/local-provisioning#net-aspire-azure-hosting-integrations) for more information on how .NET Aspire create the necessary cloud resources for local development.
166+
125167
### Local development using an existing gpt-4o-mini and ada-002 model
126168
127169
In order to use existing models: gpt-4o-mini and text-embedding-ada-002, you need to define the specific connection string in the `Products` project.
@@ -134,32 +176,24 @@ cd src/Products
134176
dotnet user-secrets set "ConnectionStrings:openaidev" "Endpoint=https://<endpoint>.openai.azure.com/;Key=<key>;"
135177
```
136178
137-
If you are using Visual Studio 2022, you can also check the user secrets from the IDE. Right click on the `Products` project and select the `Manage User Secrets` option. You can add the following configuration in the IDE.
138-
139-
```bash
140-
{
141-
"ConnectionStrings:openaidev": "Endpoint=https://<endpoint>.openai.azure.com/;Key=<key>;"
142-
}
143-
```
144-
145-
In example:
179+
This Azure OpenAI service must contain:
146180
147-
![create Codespace](./images/35UserSecretsFromVS2022.png)
181+
- a `gpt-4o-mini` model named **gpt-4o-mini**
182+
- a `text-embedding-ada-002` model named **text-embedding-ada-002**
148183
149-
150-
The `Products` project add the Azure OpenAI clients using the configuration from the User Secrets in the Dev Environment. If you want to use the services provided by the `AppHost`, open the the `program.cs`, and change this:
184+
To use these services, edit the the `program.cs`, and change this:
151185
152186
```csharp
153-
// Add Azure OpenAI client
154-
var azureOpenAiClientName = builder.Environment.IsDevelopment() ? "openaidev" : "openai";
187+
// in dev scenarios rename this to "openaidev", and check the documentation to reuse existing AOAI resources
188+
var azureOpenAiClientName = "openai";
155189
builder.AddAzureOpenAIClient(azureOpenAiClientName);
156190
```
157191
158192
to this:
159193
160194
```csharp
161-
// Add Azure OpenAI client
162-
var azureOpenAiClientName = "openai";
195+
// in dev scenarios rename this to "openaidev", and check the documentation to reuse existing AOAI resources
196+
var azureOpenAiClientName = "openaidev";
163197
builder.AddAzureOpenAIClient(azureOpenAiClientName);
164198
```
165199

src/Products/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
// Add DbContext service
2323
builder.AddSqlServerDbContext<Context>("sqldb");
2424

25-
// Add Azure OpenAI client
26-
var azureOpenAiClientName = builder.Environment.IsDevelopment() ? "openaidev" : "openai";
25+
// in dev scenarios rename this to "openaidev", and check the documentation to reuse existing AOAI resources
26+
var azureOpenAiClientName = "openai";
2727
builder.AddAzureOpenAIClient(azureOpenAiClientName);
2828

2929
// get azure openai client and create Chat client from aspire hosting configuration

src/eShopAppHost/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@
2020

2121
var products = builder.AddProject<Projects.Products>("products")
2222
.WithReference(sqldb)
23+
.WaitFor(sqldb)
2324
.WithReference(appInsights)
2425
.WithReference(aoai)
2526
.WithEnvironment("AI_ChatDeploymentName", chatDeploymentName)
2627
.WithEnvironment("AI_embeddingsDeploymentName", embeddingsDeploymentName);
2728

2829
var store = builder.AddProject<Projects.Store>("store")
2930
.WithReference(products)
31+
.WaitFor(products)
3032
.WithReference(appInsights)
3133
.WithExternalHttpEndpoints();
3234

src/eShopAppHost/appsettings.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
"Aspire.Hosting.Dcp": "Warning"
77
}
88
},
9-
"Azure": {
10-
"CredentialSource": "AzureCli"
9+
"Azure":
10+
{
11+
"AllowResourceGroupCreation": true,
12+
"CredentialSource": "AzureCli",
13+
"SubscriptionId": "< SubscriptionId >",
14+
"ResourceGroup": "< your resource group name>",
15+
"Location": "< azure region. ie: eastus2 >"
1116
}
1217
}

0 commit comments

Comments
 (0)