Skip to content

Commit 50ca0b8

Browse files
mitchdennyradical
authored andcommitted
Postgres end to end. (dotnet#2063)
* Postgres end to end. * Add manifest for reference.
1 parent 9fd3205 commit 50ca0b8

15 files changed

+498
-0
lines changed

Aspire.sln

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ParameterEndToEnd.AppHost",
229229
EndProject
230230
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ParameterEndToEnd.ApiService", "playground\ParameterEndToEnd\ParameterEndToEnd.ApiService\ParameterEndToEnd.ApiService.csproj", "{FD63D574-8512-421D-B7FC-310AFA974361}"
231231
EndProject
232+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "PostgresEndToEnd", "PostgresEndToEnd", "{2A076AC1-9201-4E9B-BCB7-5AC4F8F4AADB}"
233+
EndProject
234+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PostgresEndToEnd.AppHost", "playground\PostgresEndToEnd\PostgresEndToEnd.AppHost\PostgresEndToEnd.AppHost.csproj", "{A4C06329-56EA-4AE6-A698-D2B7B7ABE318}"
235+
EndProject
236+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PostgresEndToEnd.ApiService", "playground\PostgresEndToEnd\PostgresEndToEnd.ApiService\PostgresEndToEnd.ApiService.csproj", "{B7BC1137-25E2-4B5D-A45F-38F5BA4811A2}"
232237
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "mysql", "mysql", "{621991F1-854A-4743-835B-10CAF11A0CFF}"
233238
EndProject
234239
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MySqlDb.AppHost", "Playground\mysql\MySqlDb.AppHost\MySqlDb.AppHost.csproj", "{7E2AD00B-60E0-46C2-8640-7217D678F312}"
@@ -613,6 +618,14 @@ Global
613618
{FD63D574-8512-421D-B7FC-310AFA974361}.Debug|Any CPU.Build.0 = Debug|Any CPU
614619
{FD63D574-8512-421D-B7FC-310AFA974361}.Release|Any CPU.ActiveCfg = Release|Any CPU
615620
{FD63D574-8512-421D-B7FC-310AFA974361}.Release|Any CPU.Build.0 = Release|Any CPU
621+
{A4C06329-56EA-4AE6-A698-D2B7B7ABE318}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
622+
{A4C06329-56EA-4AE6-A698-D2B7B7ABE318}.Debug|Any CPU.Build.0 = Debug|Any CPU
623+
{A4C06329-56EA-4AE6-A698-D2B7B7ABE318}.Release|Any CPU.ActiveCfg = Release|Any CPU
624+
{A4C06329-56EA-4AE6-A698-D2B7B7ABE318}.Release|Any CPU.Build.0 = Release|Any CPU
625+
{B7BC1137-25E2-4B5D-A45F-38F5BA4811A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
626+
{B7BC1137-25E2-4B5D-A45F-38F5BA4811A2}.Debug|Any CPU.Build.0 = Debug|Any CPU
627+
{B7BC1137-25E2-4B5D-A45F-38F5BA4811A2}.Release|Any CPU.ActiveCfg = Release|Any CPU
628+
{B7BC1137-25E2-4B5D-A45F-38F5BA4811A2}.Release|Any CPU.Build.0 = Release|Any CPU
616629
{7E2AD00B-60E0-46C2-8640-7217D678F312}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
617630
{7E2AD00B-60E0-46C2-8640-7217D678F312}.Debug|Any CPU.Build.0 = Debug|Any CPU
618631
{7E2AD00B-60E0-46C2-8640-7217D678F312}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -728,6 +741,9 @@ Global
728741
{F1387494-34DE-4B31-B587-699B2E9A20CA} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
729742
{54B66163-016D-4122-9364-409AB61BC36B} = {F1387494-34DE-4B31-B587-699B2E9A20CA}
730743
{FD63D574-8512-421D-B7FC-310AFA974361} = {F1387494-34DE-4B31-B587-699B2E9A20CA}
744+
{2A076AC1-9201-4E9B-BCB7-5AC4F8F4AADB} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
745+
{A4C06329-56EA-4AE6-A698-D2B7B7ABE318} = {2A076AC1-9201-4E9B-BCB7-5AC4F8F4AADB}
746+
{B7BC1137-25E2-4B5D-A45F-38F5BA4811A2} = {2A076AC1-9201-4E9B-BCB7-5AC4F8F4AADB}
731747
{621991F1-854A-4743-835B-10CAF11A0CFF} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
732748
{7E2AD00B-60E0-46C2-8640-7217D678F312} = {621991F1-854A-4743-835B-10CAF11A0CFF}
733749
{F699F3AD-2AD9-454B-BA40-82AC3D6250FE} = {621991F1-854A-4743-835B-10CAF11A0CFF}
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.Npgsql.EntityFrameworkCore.PostgreSQL\Aspire.Npgsql.EntityFrameworkCore.PostgreSQL.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: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
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.AddNpgsqlDbContext<MyDb1Context>("db1");
11+
builder.AddNpgsqlDbContext<MyDb2Context>("db2");
12+
builder.AddNpgsqlDbContext<MyDb3Context>("db3");
13+
builder.AddNpgsqlDbContext<MyDb4Context>("db4");
14+
builder.AddNpgsqlDbContext<MyDb5Context>("db5");
15+
builder.AddNpgsqlDbContext<MyDb6Context>("db6");
16+
builder.AddNpgsqlDbContext<MyDb7Context>("db7");
17+
builder.AddNpgsqlDbContext<MyDb8Context>("db8");
18+
var app = builder.Build();
19+
20+
app.MapGet("/", async (MyDb1Context db1Context, MyDb2Context db2Context, MyDb3Context db3Context, MyDb4Context db4Context, MyDb5Context db5Context, MyDb6Context db6Context, MyDb7Context db7Context, MyDb8Context db8Context) =>
21+
{
22+
// You wouldn't normally do this on every call,
23+
// but doing it here just to make this simple.
24+
db1Context.Database.EnsureCreated();
25+
db2Context.Database.EnsureCreated();
26+
db3Context.Database.EnsureCreated();
27+
db4Context.Database.EnsureCreated();
28+
db5Context.Database.EnsureCreated();
29+
db6Context.Database.EnsureCreated();
30+
db7Context.Database.EnsureCreated();
31+
db8Context.Database.EnsureCreated();
32+
33+
// We only work with db1Context for the rest of this
34+
// since we've proven connectivity to the others for now.
35+
var entry = new Entry();
36+
await db1Context.Entries.AddAsync(entry);
37+
await db1Context.SaveChangesAsync();
38+
39+
var entries = await db1Context.Entries.ToListAsync();
40+
41+
return new
42+
{
43+
totalEntries = entries.Count,
44+
entries = entries
45+
};
46+
});
47+
48+
app.Run();
49+
50+
public class MyDb1Context(DbContextOptions<MyDb1Context> options) : DbContext(options)
51+
{
52+
protected override void OnModelCreating(ModelBuilder modelBuilder)
53+
{
54+
base.OnModelCreating(modelBuilder);
55+
56+
modelBuilder.Entity<Entry>().HasKey(e => e.Id);
57+
}
58+
59+
public DbSet<Entry> Entries { get; set; }
60+
}
61+
62+
public class MyDb2Context(DbContextOptions<MyDb2Context> options) : DbContext(options)
63+
{
64+
protected override void OnModelCreating(ModelBuilder modelBuilder)
65+
{
66+
base.OnModelCreating(modelBuilder);
67+
68+
modelBuilder.Entity<Entry>().HasKey(e => e.Id);
69+
}
70+
71+
public DbSet<Entry> Entries { get; set; }
72+
}
73+
74+
public class MyDb3Context(DbContextOptions<MyDb3Context> options) : DbContext(options)
75+
{
76+
protected override void OnModelCreating(ModelBuilder modelBuilder)
77+
{
78+
base.OnModelCreating(modelBuilder);
79+
80+
modelBuilder.Entity<Entry>().HasKey(e => e.Id);
81+
}
82+
83+
public DbSet<Entry> Entries { get; set; }
84+
}
85+
86+
public class MyDb4Context(DbContextOptions<MyDb4Context> options) : DbContext(options)
87+
{
88+
protected override void OnModelCreating(ModelBuilder modelBuilder)
89+
{
90+
base.OnModelCreating(modelBuilder);
91+
92+
modelBuilder.Entity<Entry>().HasKey(e => e.Id);
93+
}
94+
95+
public DbSet<Entry> Entries { get; set; }
96+
}
97+
98+
public class MyDb5Context(DbContextOptions<MyDb5Context> options) : DbContext(options)
99+
{
100+
protected override void OnModelCreating(ModelBuilder modelBuilder)
101+
{
102+
base.OnModelCreating(modelBuilder);
103+
104+
modelBuilder.Entity<Entry>().HasKey(e => e.Id);
105+
}
106+
107+
public DbSet<Entry> Entries { get; set; }
108+
}
109+
110+
public class MyDb6Context(DbContextOptions<MyDb6Context> options) : DbContext(options)
111+
{
112+
protected override void OnModelCreating(ModelBuilder modelBuilder)
113+
{
114+
base.OnModelCreating(modelBuilder);
115+
116+
modelBuilder.Entity<Entry>().HasKey(e => e.Id);
117+
}
118+
119+
public DbSet<Entry> Entries { get; set; }
120+
}
121+
122+
public class MyDb7Context(DbContextOptions<MyDb7Context> options) : DbContext(options)
123+
{
124+
protected override void OnModelCreating(ModelBuilder modelBuilder)
125+
{
126+
base.OnModelCreating(modelBuilder);
127+
128+
modelBuilder.Entity<Entry>().HasKey(e => e.Id);
129+
}
130+
131+
public DbSet<Entry> Entries { get; set; }
132+
}
133+
134+
public class MyDb8Context(DbContextOptions<MyDb8Context> options) : DbContext(options)
135+
{
136+
protected override void OnModelCreating(ModelBuilder modelBuilder)
137+
{
138+
base.OnModelCreating(modelBuilder);
139+
140+
modelBuilder.Entity<Entry>().HasKey(e => e.Id);
141+
}
142+
143+
public DbSet<Entry> Entries { get; set; }
144+
}
145+
146+
public class Entry
147+
{
148+
public Guid Id { get; set; } = Guid.NewGuid();
149+
}
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: 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: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net8.0</TargetFramework>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<Nullable>enable</Nullable>
8+
<IsAspireHost>true</IsAspireHost>
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<Compile Include="$(SharedDir)KnownResourceNames.cs" Link="KnownResourceNames.cs" />
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\..\..\src\Aspire.Dashboard\Aspire.Dashboard.csproj" />
17+
<ProjectReference Include="..\..\..\src\Aspire.Hosting\Aspire.Hosting.csproj" IsAspireProjectResource="false" />
18+
19+
<ProjectReference Include="..\PostgresEndToEnd.ApiService\PostgresEndToEnd.ApiService.csproj" />
20+
</ItemGroup>
21+
22+
</Project>

0 commit comments

Comments
 (0)