Skip to content

Commit ada5af1

Browse files
authored
Added a mongo playground project (#1921)
1 parent f954f61 commit ada5af1

File tree

14 files changed

+212
-0
lines changed

14 files changed

+212
-0
lines changed

Aspire.sln

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlServerEndToEnd.AppHost",
211211
EndProject
212212
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlServerEndToEnd.ApiService", "playground\SqlServerEndToEnd\SqlServerEndToEnd.ApiService\SqlServerEndToEnd.ApiService.csproj", "{78ABCF96-507B-4E5F-9265-CACC3EFD4C53}"
213213
EndProject
214+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "mongo", "mongo", "{C544D8A6-977E-40EA-8B1A-1FB2146A2108}"
215+
EndProject
216+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mongo.AppHost", "playground\mongo\Mongo.AppHost\Mongo.AppHost.csproj", "{8F132275-233C-4121-AC6F-352C902FA064}"
217+
EndProject
218+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mongo.ApiService", "playground\mongo\Mongo.ApiService\Mongo.ApiService.csproj", "{40EC38A2-69DB-4759-81C8-13F31090FEA6}"
219+
EndProject
214220
Global
215221
GlobalSection(SolutionConfigurationPlatforms) = preSolution
216222
Debug|Any CPU = Debug|Any CPU
@@ -565,6 +571,14 @@ Global
565571
{78ABCF96-507B-4E5F-9265-CACC3EFD4C53}.Debug|Any CPU.Build.0 = Debug|Any CPU
566572
{78ABCF96-507B-4E5F-9265-CACC3EFD4C53}.Release|Any CPU.ActiveCfg = Release|Any CPU
567573
{78ABCF96-507B-4E5F-9265-CACC3EFD4C53}.Release|Any CPU.Build.0 = Release|Any CPU
574+
{8F132275-233C-4121-AC6F-352C902FA064}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
575+
{8F132275-233C-4121-AC6F-352C902FA064}.Debug|Any CPU.Build.0 = Debug|Any CPU
576+
{8F132275-233C-4121-AC6F-352C902FA064}.Release|Any CPU.ActiveCfg = Release|Any CPU
577+
{8F132275-233C-4121-AC6F-352C902FA064}.Release|Any CPU.Build.0 = Release|Any CPU
578+
{40EC38A2-69DB-4759-81C8-13F31090FEA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
579+
{40EC38A2-69DB-4759-81C8-13F31090FEA6}.Debug|Any CPU.Build.0 = Debug|Any CPU
580+
{40EC38A2-69DB-4759-81C8-13F31090FEA6}.Release|Any CPU.ActiveCfg = Release|Any CPU
581+
{40EC38A2-69DB-4759-81C8-13F31090FEA6}.Release|Any CPU.Build.0 = Release|Any CPU
568582
EndGlobalSection
569583
GlobalSection(SolutionProperties) = preSolution
570584
HideSolutionNode = FALSE
@@ -664,6 +678,9 @@ Global
664678
{2CA6AB88-21EF-4488-BB1B-3A5BAD5FE2AD} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
665679
{7616FD70-6BEC-439D-B39E-A838F939C0F9} = {2CA6AB88-21EF-4488-BB1B-3A5BAD5FE2AD}
666680
{78ABCF96-507B-4E5F-9265-CACC3EFD4C53} = {2CA6AB88-21EF-4488-BB1B-3A5BAD5FE2AD}
681+
{C544D8A6-977E-40EA-8B1A-1FB2146A2108} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0}
682+
{8F132275-233C-4121-AC6F-352C902FA064} = {C544D8A6-977E-40EA-8B1A-1FB2146A2108}
683+
{40EC38A2-69DB-4759-81C8-13F31090FEA6} = {C544D8A6-977E-40EA-8B1A-1FB2146A2108}
667684
EndGlobalSection
668685
GlobalSection(ExtensibilityGlobals) = postSolution
669686
SolutionGuid = {6DCEDFEC-988E-4CB3-B45B-191EB5086E0C}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
<InvariantGlobalization>true</InvariantGlobalization>
8+
<NoWarn>$(NoWarn);CS8002</NoWarn> <!-- MongoDB packages are not signed -->
9+
</PropertyGroup>
10+
11+
<ItemGroup>
12+
<ProjectReference Include="..\..\..\src\Components\Aspire.MongoDB.Driver\Aspire.MongoDB.Driver.csproj" />
13+
<ProjectReference Include="..\..\Playground.ServiceDefaults\Playground.ServiceDefaults.csproj" />
14+
</ItemGroup>
15+
16+
</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:5301
2+
3+
GET {{CosmosEndToEnd.ApiService_HostAddress}}/weatherforecast/
4+
Accept: application/json
5+
6+
###
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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 MongoDB.Bson.Serialization.Attributes;
5+
using MongoDB.Bson;
6+
using MongoDB.Driver;
7+
8+
var builder = WebApplication.CreateBuilder(args);
9+
10+
builder.AddServiceDefaults();
11+
builder.AddMongoDBClient("mongo");
12+
13+
var app = builder.Build();
14+
15+
app.MapGet("/", async (IMongoClient mongoClient) =>
16+
{
17+
const string collectionName = "entries";
18+
19+
var db = mongoClient.GetDatabase("db");
20+
await db.CreateCollectionAsync(collectionName);
21+
22+
// Add an entry to the database on each request.
23+
var newEntry = new Entry();
24+
await db.GetCollection<Entry>(collectionName).InsertOneAsync(newEntry);
25+
26+
var items = await db.GetCollection<Entry>(collectionName).FindAsync(_ => true);
27+
28+
return items.ToListAsync();
29+
});
30+
31+
app.Run();
32+
33+
public class Entry
34+
{
35+
[BsonId]
36+
[BsonRepresentation(BsonType.ObjectId)]
37+
public string? Id { get; set; }
38+
}
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:5301",
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: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
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="..\..\..\src\Aspire.Hosting\Utils\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.Azure\Aspire.Hosting.Azure.csproj" IsAspireProjectResource="false" />
18+
<ProjectReference Include="..\..\..\src\Aspire.Hosting\Aspire.Hosting.csproj" IsAspireProjectResource="false" />
19+
20+
<ProjectReference Include="..\Mongo.ApiService\Mongo.ApiService.csproj" />
21+
</ItemGroup>
22+
23+
</Project>

0 commit comments

Comments
 (0)