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

βœ… Merge main into live #1615

Merged
merged 2 commits into from
Sep 10, 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
4 changes: 4 additions & 0 deletions docs/database/ef-core-migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,7 @@ Now that the migration service is configured, run the app to test the migrations
## Get the code

You can find the [completed sample app on GitHub](https://github.com/MicrosoftDocs/aspire-docs-samples/tree/solution/SupportTicketApi).

## More sample code

The [Aspire Shop](/samples/dotnet/aspire-samples/aspire-shop/) sample app uses this approach to apply migrations. See the `AspireShop.CatalogDbManager` project for the migration service implementation.
14 changes: 11 additions & 3 deletions docs/database/sql-server-integrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,23 @@ In the _:::no-loc text="Program.cs":::_ file of the _AspireSQLEFCore_ project, a

This method accomplishes the following tasks:

- Registers a `TicketDbContext` with the DI container for connecting to the containerized Azure SQL Database.
- Registers a `TicketContext` with the DI container for connecting to the containerized Azure SQL Database.
- Automatically enable corresponding health checks, logging, and telemetry.

## Migrate and seed the database
## Create the database

While developing locally, you need to create a database inside the SQL Server container. Update the _:::no-loc text="Program.cs":::_ file with the following code to automatically run Entity Framework migrations during startup.
While developing locally, you need to create a database inside the SQL Server container. Update the _:::no-loc text="Program.cs":::_ file with the following code:

:::code language="csharp" source="snippets/tutorial/AspireSQLEFCore/AspireSQLEFCore/Program.cs" range="1-30" highlight="16-30":::

The preceding code:

- Checks if the app is running in a development environment.
- If it is, it retrieves the `TicketContext` service from the DI container and calls `Database.EnsureCreated()` to create the database if it doesn't already exist.

> [!NOTE]
> Note that `EnsureCreated()` is not suitable for production environments, and it only creates the database as defined in the context. It doesn't apply any migrations. For more information on Entity Framework Core migrations in .NET Aspire, see [Apply Entity Framework Core migrations in .NET Aspire](ef-core-migrations.md).
## Create the form

The app requires a form for the user to be able to submit support ticket information and save the entry to the database.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "weatherforecast",
"applicationUrl": "http://localhost:5324",
"applicationUrl": "http://localhost:5381",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand All @@ -16,7 +16,7 @@
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "weatherforecast",
"applicationUrl": "https://localhost:7518;http://localhost:5324",
"applicationUrl": "https://localhost:7369;http://localhost:5381",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>c003beee-3095-46bd-a5fb-85f0280d1403</UserSecretsId>
<UserSecretsId>8832f6df-f7d3-4c65-8eab-22abf6e43ee8</UserSecretsId>
</PropertyGroup>

<ItemGroup>
Expand All @@ -16,7 +16,6 @@

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="8.2.0" />
<PackageReference Include="Aspire.Hosting.Redis" Version="8.2.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
var builder = DistributedApplication.CreateBuilder(args);

var cache = builder.AddRedis("cache");

var apiService = builder.AddProject<Projects.AspireApp_ApiService>("apiservice");

builder.AddProject<Projects.AspireApp_Web>("webfrontend")
.WithExternalHttpEndpoints()
.WithReference(cache)
.WithReference(apiService);

builder.Build().Run();
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17256;http://localhost:15121",
"applicationUrl": "https://localhost:17244;http://localhost:15088",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21034",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22227"
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21193",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22213"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15121",
"applicationUrl": "http://localhost:15088",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19034",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20015"
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19275",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20199"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<ItemGroup>
<PackageReference Include="Aspire.Hosting.Testing" Version="8.2.0" />
<PackageReference Include="MSTest" Version="3.5.2" />
<PackageReference Include="MSTest" Version="3.4.3" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
ο»Ώnamespace AspireApp.Tests;

[TestClass]
public class EnvVarTests
{
[TestMethod]
public async Task WebResourceEnvVarsResolveToApiService()
{
// Arrange
var appHost = await DistributedApplicationTestingBuilder
.CreateAsync<Projects.AspireApp_AppHost>();

var frontend = (IResourceWithEnvironment)appHost.Resources
.Single(static r => r.Name == "webfrontend");

// Act
var envVars = await frontend.GetEnvironmentVariableValuesAsync(
DistributedApplicationOperation.Publish);

// Assert
CollectionAssert.Contains(envVars,
new KeyValuePair<string, string>(
key: "services__apiservice__https__0",
value: "{apiservice.bindings.https.url}"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task GetWebResourceRootReturnsOkStatusCode()

var resourceNotificationService = app.Services
.GetRequiredService<ResourceNotificationService>();

await app.StartAsync();

// Act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,4 @@
<ProjectReference Include="..\AspireApp.ServiceDefaults\AspireApp.ServiceDefaults.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Aspire.StackExchange.Redis.OutputCaching" Version="8.2.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@

// Add service defaults & Aspire components.
builder.AddServiceDefaults();
builder.AddRedisOutputCache("cache");

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

builder.Services.AddOutputCache();

builder.Services.AddHttpClient<WeatherApiClient>(client =>
{
// This URL uses "https+http://" to indicate HTTPS is preferred over HTTP.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:5188",
"applicationUrl": "http://localhost:5154",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand All @@ -14,7 +14,7 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:7034;http://localhost:5188",
"applicationUrl": "https://localhost:7226;http://localhost:5154",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ h1:focus {
}

.invalid {
outline: 1px solid #e51880;
outline: 1px solid #e51540;
}

.validation-message {
color: #e51880;
color: #e51540;
}

.blazor-error-boundary {
Expand Down
54 changes: 27 additions & 27 deletions docs/fundamentals/snippets/testing/mstest/AspireApp.sln
Original file line number Diff line number Diff line change
@@ -1,48 +1,48 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.12.35125.258
VisualStudioVersion = 17.12.35209.166
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspireApp.AppHost", "AspireApp.AppHost\AspireApp.AppHost.csproj", "{12497C1B-3914-4F0A-B66E-169E6CD32F7C}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspireApp.AppHost", "AspireApp.AppHost\AspireApp.AppHost.csproj", "{EC46758A-CEC8-4167-A411-BA7C8FAA0568}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspireApp.ServiceDefaults", "AspireApp.ServiceDefaults\AspireApp.ServiceDefaults.csproj", "{DF30B3ED-82B3-4E9F-9704-371B86362514}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspireApp.ServiceDefaults", "AspireApp.ServiceDefaults\AspireApp.ServiceDefaults.csproj", "{C03045B9-8C3D-4E14-837F-E74D7E02D00A}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspireApp.ApiService", "AspireApp.ApiService\AspireApp.ApiService.csproj", "{7DDDF326-E0AC-4AEE-85B2-69FA564E9465}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspireApp.ApiService", "AspireApp.ApiService\AspireApp.ApiService.csproj", "{4F099168-2B47-4298-AB97-0ECF25E3C380}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspireApp.Web", "AspireApp.Web\AspireApp.Web.csproj", "{AD54E041-CB6B-4E4E-948A-1B054E7FE236}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspireApp.Web", "AspireApp.Web\AspireApp.Web.csproj", "{5D051D94-C160-4A30-A66C-598729909737}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspireApp.Tests", "AspireApp.Tests\AspireApp.Tests.csproj", "{FE61106C-EB7D-455D-AE61-AB9636668A47}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AspireApp.Tests", "AspireApp.Tests\AspireApp.Tests.csproj", "{F46802CC-1977-415B-830F-8D9088DA822A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{12497C1B-3914-4F0A-B66E-169E6CD32F7C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{12497C1B-3914-4F0A-B66E-169E6CD32F7C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{12497C1B-3914-4F0A-B66E-169E6CD32F7C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{12497C1B-3914-4F0A-B66E-169E6CD32F7C}.Release|Any CPU.Build.0 = Release|Any CPU
{DF30B3ED-82B3-4E9F-9704-371B86362514}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{DF30B3ED-82B3-4E9F-9704-371B86362514}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DF30B3ED-82B3-4E9F-9704-371B86362514}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DF30B3ED-82B3-4E9F-9704-371B86362514}.Release|Any CPU.Build.0 = Release|Any CPU
{7DDDF326-E0AC-4AEE-85B2-69FA564E9465}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7DDDF326-E0AC-4AEE-85B2-69FA564E9465}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7DDDF326-E0AC-4AEE-85B2-69FA564E9465}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7DDDF326-E0AC-4AEE-85B2-69FA564E9465}.Release|Any CPU.Build.0 = Release|Any CPU
{AD54E041-CB6B-4E4E-948A-1B054E7FE236}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AD54E041-CB6B-4E4E-948A-1B054E7FE236}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AD54E041-CB6B-4E4E-948A-1B054E7FE236}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AD54E041-CB6B-4E4E-948A-1B054E7FE236}.Release|Any CPU.Build.0 = Release|Any CPU
{FE61106C-EB7D-455D-AE61-AB9636668A47}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{FE61106C-EB7D-455D-AE61-AB9636668A47}.Debug|Any CPU.Build.0 = Debug|Any CPU
{FE61106C-EB7D-455D-AE61-AB9636668A47}.Release|Any CPU.ActiveCfg = Release|Any CPU
{FE61106C-EB7D-455D-AE61-AB9636668A47}.Release|Any CPU.Build.0 = Release|Any CPU
{EC46758A-CEC8-4167-A411-BA7C8FAA0568}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EC46758A-CEC8-4167-A411-BA7C8FAA0568}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EC46758A-CEC8-4167-A411-BA7C8FAA0568}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EC46758A-CEC8-4167-A411-BA7C8FAA0568}.Release|Any CPU.Build.0 = Release|Any CPU
{C03045B9-8C3D-4E14-837F-E74D7E02D00A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C03045B9-8C3D-4E14-837F-E74D7E02D00A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C03045B9-8C3D-4E14-837F-E74D7E02D00A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C03045B9-8C3D-4E14-837F-E74D7E02D00A}.Release|Any CPU.Build.0 = Release|Any CPU
{4F099168-2B47-4298-AB97-0ECF25E3C380}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F099168-2B47-4298-AB97-0ECF25E3C380}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F099168-2B47-4298-AB97-0ECF25E3C380}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F099168-2B47-4298-AB97-0ECF25E3C380}.Release|Any CPU.Build.0 = Release|Any CPU
{5D051D94-C160-4A30-A66C-598729909737}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5D051D94-C160-4A30-A66C-598729909737}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5D051D94-C160-4A30-A66C-598729909737}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5D051D94-C160-4A30-A66C-598729909737}.Release|Any CPU.Build.0 = Release|Any CPU
{F46802CC-1977-415B-830F-8D9088DA822A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F46802CC-1977-415B-830F-8D9088DA822A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F46802CC-1977-415B-830F-8D9088DA822A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F46802CC-1977-415B-830F-8D9088DA822A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A88DD160-8742-4E48-ABE5-44D456516039}
SolutionGuid = {F2599B42-2481-4C8F-AC79-3029FC2FC444}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "weatherforecast",
"applicationUrl": "http://localhost:5317",
"applicationUrl": "http://localhost:5314",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand All @@ -16,7 +16,7 @@
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "weatherforecast",
"applicationUrl": "https://localhost:7578;http://localhost:5317",
"applicationUrl": "https://localhost:7560;http://localhost:5314",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>b85dd0bb-63ef-4db6-b7a4-06df00663b65</UserSecretsId>
<UserSecretsId>2eb28899-ee86-44a2-b637-287cfc49eeaf</UserSecretsId>
</PropertyGroup>

<ItemGroup>
Expand All @@ -16,7 +16,6 @@

<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="8.2.0" />
<PackageReference Include="Aspire.Hosting.Redis" Version="8.2.0" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
var builder = DistributedApplication.CreateBuilder(args);

var cache = builder.AddRedis("cache");

var apiService = builder.AddProject<Projects.AspireApp_ApiService>("apiservice");

builder.AddProject<Projects.AspireApp_Web>("webfrontend")
.WithExternalHttpEndpoints()
.WithReference(cache)
.WithReference(apiService);

builder.Build().Run();
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "https://localhost:17035;http://localhost:15120",
"applicationUrl": "https://localhost:17064;http://localhost:15294",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21139",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22100"
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "https://localhost:21173",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "https://localhost:22005"
}
},
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"applicationUrl": "http://localhost:15120",
"applicationUrl": "http://localhost:15294",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development",
"DOTNET_ENVIRONMENT": "Development",
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19016",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20120"
"DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:19025",
"DOTNET_RESOURCE_SERVICE_ENDPOINT_URL": "http://localhost:20131"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

<ItemGroup>
<PackageReference Include="Aspire.Hosting.Testing" Version="8.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.11.0" />
<PackageReference Include="NUnit" Version="4.2.2" />
<PackageReference Include="NUnit.Analyzers" Version="4.3.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.6.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="NUnit" Version="4.1.0" />
<PackageReference Include="NUnit.Analyzers" Version="4.2.0" />
<PackageReference Include="NUnit3TestAdapter" Version="4.5.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading
Loading