Skip to content

Commit a21135c

Browse files
authored
Playground app for SQL Server resources (uses EF). (#1895)
* End to end SQL playground.
1 parent 6fe5242 commit a21135c

File tree

14 files changed

+221
-0
lines changed

14 files changed

+221
-0
lines changed

Aspire.sln

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Pomelo.EntityFramewo
205205
EndProject
206206
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.Pomelo.EntityFrameworkCore.MySql.Tests", "tests\Aspire.Pomelo.EntityFrameworkCore.MySql.Tests\Aspire.Pomelo.EntityFrameworkCore.MySql.Tests.csproj", "{BFAF55A8-A737-4EC1-BBA2-76001A8F16E0}"
207207
EndProject
208+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SqlServerEndToEnd", "SqlServerEndToEnd", "{2CA6AB88-21EF-4488-BB1B-3A5BAD5FE2AD}"
209+
EndProject
210+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlServerEndToEnd.AppHost", "playground\SqlServerEndToEnd\SqlServerEndToEnd.AppHost\SqlServerEndToEnd.AppHost.csproj", "{7616FD70-6BEC-439D-B39E-A838F939C0F9}"
211+
EndProject
212+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlServerEndToEnd.ApiService", "playground\SqlServerEndToEnd\SqlServerEndToEnd.ApiService\SqlServerEndToEnd.ApiService.csproj", "{78ABCF96-507B-4E5F-9265-CACC3EFD4C53}"
213+
EndProject
208214
Global
209215
GlobalSection(SolutionConfigurationPlatforms) = preSolution
210216
Debug|Any CPU = Debug|Any CPU
@@ -551,6 +557,14 @@ Global
551557
{BFAF55A8-A737-4EC1-BBA2-76001A8F16E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
552558
{BFAF55A8-A737-4EC1-BBA2-76001A8F16E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
553559
{BFAF55A8-A737-4EC1-BBA2-76001A8F16E0}.Release|Any CPU.Build.0 = Release|Any CPU
560+
{7616FD70-6BEC-439D-B39E-A838F939C0F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
561+
{7616FD70-6BEC-439D-B39E-A838F939C0F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
562+
{7616FD70-6BEC-439D-B39E-A838F939C0F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
563+
{7616FD70-6BEC-439D-B39E-A838F939C0F9}.Release|Any CPU.Build.0 = Release|Any CPU
564+
{78ABCF96-507B-4E5F-9265-CACC3EFD4C53}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
565+
{78ABCF96-507B-4E5F-9265-CACC3EFD4C53}.Debug|Any CPU.Build.0 = Debug|Any CPU
566+
{78ABCF96-507B-4E5F-9265-CACC3EFD4C53}.Release|Any CPU.ActiveCfg = Release|Any CPU
567+
{78ABCF96-507B-4E5F-9265-CACC3EFD4C53}.Release|Any CPU.Build.0 = Release|Any CPU
554568
EndGlobalSection
555569
GlobalSection(SolutionProperties) = preSolution
556570
HideSolutionNode = FALSE
@@ -647,6 +661,9 @@ Global
647661
{25208C6F-0A9D-4D60-9EDD-256C9891B1CD} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
648662
{C565532A-0754-44FE-A0C7-78D5338DDBCA} = {27381127-6C45-4B4C-8F18-41FF48DFE4B2}
649663
{BFAF55A8-A737-4EC1-BBA2-76001A8F16E0} = {4981B3A5-4AFD-4191-BF7D-8692D9783D60}
664+
{2CA6AB88-21EF-4488-BB1B-3A5BAD5FE2AD} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
665+
{7616FD70-6BEC-439D-B39E-A838F939C0F9} = {2CA6AB88-21EF-4488-BB1B-3A5BAD5FE2AD}
666+
{78ABCF96-507B-4E5F-9265-CACC3EFD4C53} = {2CA6AB88-21EF-4488-BB1B-3A5BAD5FE2AD}
650667
EndGlobalSection
651668
GlobalSection(ExtensibilityGlobals) = postSolution
652669
SolutionGuid = {6DCEDFEC-988E-4CB3-B45B-191EB5086E0C}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Microsoft.EntityFrameworkCore;
5+
6+
var builder = WebApplication.CreateBuilder(args);
7+
8+
builder.AddServiceDefaults();
9+
10+
builder.AddSqlServerDbContext<MyDbContext>("db");
11+
12+
var app = builder.Build();
13+
14+
app.MapGet("/", async (MyDbContext context) =>
15+
{
16+
// You wouldn't normally do this on every call,
17+
// but doing it here just to make this simple.
18+
context.Database.EnsureCreated();
19+
20+
var entry = new Entry();
21+
await context.Entries.AddAsync(entry);
22+
await context.SaveChangesAsync();
23+
24+
var entries = await context.Entries.ToListAsync();
25+
26+
return new
27+
{
28+
totalEntries = entries.Count,
29+
entries = entries
30+
};
31+
});
32+
33+
app.Run();
34+
35+
public class MyDbContext(DbContextOptions<MyDbContext> options) : DbContext(options)
36+
{
37+
protected override void OnModelCreating(ModelBuilder modelBuilder)
38+
{
39+
base.OnModelCreating(modelBuilder);
40+
41+
modelBuilder.Entity<Entry>().HasKey(e => e.Id);
42+
}
43+
44+
public DbSet<Entry> Entries { get; set; }
45+
}
46+
47+
public class Entry
48+
{
49+
public Guid Id { get; set; } = Guid.NewGuid();
50+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"$schema": "http://json.schemastore.org/launchsettings.json",
3+
"profiles": {
4+
"http": {
5+
"commandName": "Project",
6+
"dotnetRunMessages": true,
7+
"launchBrowser": true,
8+
"applicationUrl": "http://localhost:5180",
9+
"environmentVariables": {
10+
"ASPNETCORE_ENVIRONMENT": "Development"
11+
}
12+
}
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<ProjectReference Include="..\..\..\src\Components\Aspire.Microsoft.EntityFrameworkCore.SqlServer\Aspire.Microsoft.EntityFrameworkCore.SqlServer.csproj" />
11+
<ProjectReference Include="..\..\Playground.ServiceDefaults\Playground.ServiceDefaults.csproj" />
12+
</ItemGroup>
13+
14+
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@CosmosEndToEnd.ApiService_HostAddress = http://localhost:5193
2+
3+
GET {{SqlServerEndToEnd.ApiService_HostAddress}}/weatherforecast/
4+
Accept: application/json
5+
6+
###
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
}
8+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
6+
}
7+
},
8+
"AllowedHosts": "*"
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project>
2+
3+
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" />
4+
5+
<!-- NOTE: This line is only required because we are using P2P references, not NuGet. It will not exist in real apps. -->
6+
<Import Project="../../../src/Aspire.Hosting/build/Aspire.Hosting.props" />
7+
8+
</Project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project>
2+
3+
<Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" />
4+
5+
<!-- NOTE: These lines are only required because we are using P2P references, not NuGet. They will not exist in real apps. -->
6+
<Import Project="..\..\..\src\Aspire.Hosting\build\Aspire.Hosting.targets" />
7+
<Import Project="..\..\..\src\Aspire.Hosting.Sdk\SDK\Sdk.targets" />
8+
9+
</Project>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
var builder = DistributedApplication.CreateBuilder(args);
5+
6+
var db = builder.AddSqlServer("sql").AddDatabase("db");
7+
8+
builder.AddProject<Projects.SqlServerEndToEnd_ApiService>("api")
9+
.WithReference(db);
10+
11+
// This project is only added in playground projects to support development/debugging
12+
// of the dashboard. It is not required in end developer code. Comment out this code
13+
// to test end developer dashboard launch experience. Refer to Directory.Build.props
14+
// for the path to the dashboard binary (defaults to the Aspire.Dashboard bin output
15+
// in the artifacts dir).
16+
//builder.AddProject<Projects.Aspire_Dashboard>(KnownResourceNames.AspireDashboard);
17+
18+
builder.Build().Run();

0 commit comments

Comments
 (0)