diff --git a/Aspire.sln b/Aspire.sln index 9b7c97973bc..86125601ded 100644 --- a/Aspire.sln +++ b/Aspire.sln @@ -211,6 +211,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlServerEndToEnd.AppHost", EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SqlServerEndToEnd.ApiService", "playground\SqlServerEndToEnd\SqlServerEndToEnd.ApiService\SqlServerEndToEnd.ApiService.csproj", "{78ABCF96-507B-4E5F-9265-CACC3EFD4C53}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "mongo", "mongo", "{C544D8A6-977E-40EA-8B1A-1FB2146A2108}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mongo.AppHost", "playground\mongo\Mongo.AppHost\Mongo.AppHost.csproj", "{8F132275-233C-4121-AC6F-352C902FA064}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Mongo.ApiService", "playground\mongo\Mongo.ApiService\Mongo.ApiService.csproj", "{40EC38A2-69DB-4759-81C8-13F31090FEA6}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -565,6 +571,14 @@ Global {78ABCF96-507B-4E5F-9265-CACC3EFD4C53}.Debug|Any CPU.Build.0 = Debug|Any CPU {78ABCF96-507B-4E5F-9265-CACC3EFD4C53}.Release|Any CPU.ActiveCfg = Release|Any CPU {78ABCF96-507B-4E5F-9265-CACC3EFD4C53}.Release|Any CPU.Build.0 = Release|Any CPU + {8F132275-233C-4121-AC6F-352C902FA064}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8F132275-233C-4121-AC6F-352C902FA064}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8F132275-233C-4121-AC6F-352C902FA064}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8F132275-233C-4121-AC6F-352C902FA064}.Release|Any CPU.Build.0 = Release|Any CPU + {40EC38A2-69DB-4759-81C8-13F31090FEA6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {40EC38A2-69DB-4759-81C8-13F31090FEA6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {40EC38A2-69DB-4759-81C8-13F31090FEA6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {40EC38A2-69DB-4759-81C8-13F31090FEA6}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -664,6 +678,9 @@ Global {2CA6AB88-21EF-4488-BB1B-3A5BAD5FE2AD} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0} {7616FD70-6BEC-439D-B39E-A838F939C0F9} = {2CA6AB88-21EF-4488-BB1B-3A5BAD5FE2AD} {78ABCF96-507B-4E5F-9265-CACC3EFD4C53} = {2CA6AB88-21EF-4488-BB1B-3A5BAD5FE2AD} + {C544D8A6-977E-40EA-8B1A-1FB2146A2108} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0} + {8F132275-233C-4121-AC6F-352C902FA064} = {C544D8A6-977E-40EA-8B1A-1FB2146A2108} + {40EC38A2-69DB-4759-81C8-13F31090FEA6} = {C544D8A6-977E-40EA-8B1A-1FB2146A2108} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {6DCEDFEC-988E-4CB3-B45B-191EB5086E0C} diff --git a/playground/mongo/Mongo.ApiService/Mongo.ApiService.csproj b/playground/mongo/Mongo.ApiService/Mongo.ApiService.csproj new file mode 100644 index 00000000000..2bb74e8b7bd --- /dev/null +++ b/playground/mongo/Mongo.ApiService/Mongo.ApiService.csproj @@ -0,0 +1,16 @@ + + + + net8.0 + enable + enable + true + $(NoWarn);CS8002 + + + + + + + + diff --git a/playground/mongo/Mongo.ApiService/Mongo.ApiService.http b/playground/mongo/Mongo.ApiService/Mongo.ApiService.http new file mode 100644 index 00000000000..f0fd72181d5 --- /dev/null +++ b/playground/mongo/Mongo.ApiService/Mongo.ApiService.http @@ -0,0 +1,6 @@ +@CosmosEndToEnd.ApiService_HostAddress = http://localhost:5301 + +GET {{CosmosEndToEnd.ApiService_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/playground/mongo/Mongo.ApiService/Program.cs b/playground/mongo/Mongo.ApiService/Program.cs new file mode 100644 index 00000000000..75cdc359e5a --- /dev/null +++ b/playground/mongo/Mongo.ApiService/Program.cs @@ -0,0 +1,38 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using MongoDB.Bson.Serialization.Attributes; +using MongoDB.Bson; +using MongoDB.Driver; + +var builder = WebApplication.CreateBuilder(args); + +builder.AddServiceDefaults(); +builder.AddMongoDBClient("mongo"); + +var app = builder.Build(); + +app.MapGet("/", async (IMongoClient mongoClient) => +{ + const string collectionName = "entries"; + + var db = mongoClient.GetDatabase("db"); + await db.CreateCollectionAsync(collectionName); + + // Add an entry to the database on each request. + var newEntry = new Entry(); + await db.GetCollection(collectionName).InsertOneAsync(newEntry); + + var items = await db.GetCollection(collectionName).FindAsync(_ => true); + + return items.ToListAsync(); +}); + +app.Run(); + +public class Entry +{ + [BsonId] + [BsonRepresentation(BsonType.ObjectId)] + public string? Id { get; set; } +} diff --git a/playground/mongo/Mongo.ApiService/Properties/launchSettings.json b/playground/mongo/Mongo.ApiService/Properties/launchSettings.json new file mode 100644 index 00000000000..3a26ce01363 --- /dev/null +++ b/playground/mongo/Mongo.ApiService/Properties/launchSettings.json @@ -0,0 +1,14 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:5301", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/playground/mongo/Mongo.ApiService/appsettings.Development.json b/playground/mongo/Mongo.ApiService/appsettings.Development.json new file mode 100644 index 00000000000..0c208ae9181 --- /dev/null +++ b/playground/mongo/Mongo.ApiService/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/playground/mongo/Mongo.ApiService/appsettings.json b/playground/mongo/Mongo.ApiService/appsettings.json new file mode 100644 index 00000000000..10f68b8c8b4 --- /dev/null +++ b/playground/mongo/Mongo.ApiService/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/playground/mongo/Mongo.AppHost/Directory.Build.props b/playground/mongo/Mongo.AppHost/Directory.Build.props new file mode 100644 index 00000000000..b9b39c05e81 --- /dev/null +++ b/playground/mongo/Mongo.AppHost/Directory.Build.props @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/playground/mongo/Mongo.AppHost/Directory.Build.targets b/playground/mongo/Mongo.AppHost/Directory.Build.targets new file mode 100644 index 00000000000..b7ba77268f8 --- /dev/null +++ b/playground/mongo/Mongo.AppHost/Directory.Build.targets @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/playground/mongo/Mongo.AppHost/Mongo.AppHost.csproj b/playground/mongo/Mongo.AppHost/Mongo.AppHost.csproj new file mode 100644 index 00000000000..4d919522198 --- /dev/null +++ b/playground/mongo/Mongo.AppHost/Mongo.AppHost.csproj @@ -0,0 +1,23 @@ + + + + Exe + net8.0 + enable + enable + true + + + + + + + + + + + + + + + diff --git a/playground/mongo/Mongo.AppHost/Program.cs b/playground/mongo/Mongo.AppHost/Program.cs new file mode 100644 index 00000000000..fad385ca1fc --- /dev/null +++ b/playground/mongo/Mongo.AppHost/Program.cs @@ -0,0 +1,18 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +var builder = DistributedApplication.CreateBuilder(args); + +var db = builder.AddMongoDB("mongo"); + +builder.AddProject("api") + .WithReference(db); + +// This project is only added in playground projects to support development/debugging +// of the dashboard. It is not required in end developer code. Comment out this code +// to test end developer dashboard launch experience. Refer to Directory.Build.props +// for the path to the dashboard binary (defaults to the Aspire.Dashboard bin output +// in the artifacts dir). +builder.AddProject(KnownResourceNames.AspireDashboard); + +builder.Build().Run(); diff --git a/playground/mongo/Mongo.AppHost/Properties/launchSettings.json b/playground/mongo/Mongo.AppHost/Properties/launchSettings.json new file mode 100644 index 00000000000..16aca777b1e --- /dev/null +++ b/playground/mongo/Mongo.AppHost/Properties/launchSettings.json @@ -0,0 +1,29 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "applicationUrl": "http://localhost:15888", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "DOTNET_ENVIRONMENT": "Development", + "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16175", + "DOTNET_ASPIRE_SHOW_DASHBOARD_RESOURCES": "true" // Display dashboard resource in console for local development + } + }, + "generate-manifest": { + "commandName": "Project", + "launchBrowser": true, + "dotnetRunMessages": true, + "commandLineArgs": "--publisher manifest --output-path aspire-manifest.json", + "applicationUrl": "http://localhost:15888", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development", + "DOTNET_ENVIRONMENT": "Development", + "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16175" + } + } + } +} diff --git a/playground/mongo/Mongo.AppHost/appsettings.Development.json b/playground/mongo/Mongo.AppHost/appsettings.Development.json new file mode 100644 index 00000000000..0c208ae9181 --- /dev/null +++ b/playground/mongo/Mongo.AppHost/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/playground/mongo/Mongo.AppHost/appsettings.json b/playground/mongo/Mongo.AppHost/appsettings.json new file mode 100644 index 00000000000..31c092aa450 --- /dev/null +++ b/playground/mongo/Mongo.AppHost/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning", + "Aspire.Hosting.Dcp": "Warning" + } + } +}