-
Notifications
You must be signed in to change notification settings - Fork 720
Add Cosmos playground code. #1697
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
Changes from 6 commits
26a8c44
aef819f
e4e706c
b2b3c40
fbba8cf
db955d7
56b82b7
6798647
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk.Web"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <InvariantGlobalization>true</InvariantGlobalization> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\Components\Aspire.Microsoft.Azure.Cosmos\Aspire.Microsoft.Azure.Cosmos.csproj" /> | ||
| <ProjectReference Include="..\CosmosEndToEnd.ServiceDefaults\CosmosEndToEnd.ServiceDefaults.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| @CosmosEndToEnd.ApiService_HostAddress = http://localhost:5193 | ||
|
|
||
| GET {{CosmosEndToEnd.ApiService_HostAddress}}/weatherforecast/ | ||
| Accept: application/json | ||
|
|
||
| ### |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Microsoft.Azure.Cosmos; | ||
| using Newtonsoft.Json; | ||
|
|
||
| var sessionId = Guid.NewGuid().ToString(); | ||
mitchdenny marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| var builder = WebApplication.CreateBuilder(args); | ||
|
|
||
| builder.AddServiceDefaults(); | ||
| builder.AddAzureCosmosDB("db", settings => | ||
| { | ||
| settings.IgnoreEmulatorCertificate = true; | ||
| }); | ||
|
|
||
| var app = builder.Build(); | ||
|
|
||
| app.MapGet("/", async (CosmosClient cosmosClient) => | ||
| { | ||
| var db = (await cosmosClient.CreateDatabaseIfNotExistsAsync("db")).Database; | ||
| var container = (await db.CreateContainerIfNotExistsAsync("entries", "/sessionId")).Container; | ||
|
|
||
| // Add an entry to the database on each request. | ||
| var newEntry = new Entry() { Id = Guid.NewGuid().ToString(), SessionId = Guid.NewGuid().ToString() }; | ||
| await container.CreateItemAsync(newEntry).ConfigureAwait(false); | ||
mitchdenny marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| var entries = new List<Entry>(); | ||
| var iterator = container.GetItemQueryIterator<Entry>(requestOptions: new QueryRequestOptions() { MaxItemCount = 5 }); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ealsur - will this use query serialization? If so, it's not going to use the S.T.J serializer until Azure/azure-cosmos-dotnet-v3#4138 ships and your serializer is updated with the new API There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Queries work well with Custom Serializer. What does not work well is LINQ Queries There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This call here is effectively a ReadFeed operation (a query without any query text) |
||
|
|
||
| var batchCount = 0; | ||
| while (iterator.HasMoreResults) | ||
| { | ||
| batchCount++; | ||
| var batch = await iterator.ReadNextAsync().ConfigureAwait(false); | ||
mitchdenny marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| foreach (var entry in batch) | ||
| { | ||
| entries.Add(entry); | ||
| } | ||
| } | ||
|
|
||
| return new | ||
| { | ||
| batchCount = batchCount, | ||
| totalEntries = entries.Count, | ||
| entries = entries | ||
| }; | ||
| }); | ||
|
|
||
| app.Run(); | ||
|
|
||
| public class Entry | ||
| { | ||
| [JsonProperty("id")] | ||
| public string? Id { get; set; } | ||
|
|
||
| [JsonProperty("sessionId")] | ||
| public string? SessionId { get; set; } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "$schema": "http://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "http://localhost:5193", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development" | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| }, | ||
| "AllowedHosts": "*" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <IsAspireHost>true</IsAspireHost> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\..\..\Aspire.Hosting.Azure\Aspire.Hosting.Azure.csproj" /> | ||
| <ProjectReference Include="..\..\..\Aspire.Hosting\Aspire.Hosting.csproj" /> | ||
| <ProjectReference Include="..\CosmosEndToEnd.ApiService\CosmosEndToEnd.ApiService.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <Project> | ||
|
|
||
| <Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.props', '$(MSBuildThisFileDirectory)../'))" /> | ||
|
|
||
| <!-- NOTE: This line is only required because we are using P2P references, not NuGet. It will not exist in real apps. --> | ||
| <Import Project="../../../Aspire.Hosting/build/Aspire.Hosting.props" /> | ||
|
|
||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <Project> | ||
|
|
||
| <Import Project="$([MSBuild]::GetPathOfFileAbove('Directory.Build.targets', '$(MSBuildThisFileDirectory)../'))" /> | ||
|
|
||
| <!-- NOTE: This line is only required because we are using P2P references, not NuGet. It will not exist in real apps. --> | ||
| <Import Project="../../../Aspire.Hosting/build/Aspire.Hosting.targets" /> | ||
|
|
||
| </Project> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // 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.AddAzureCosmosDB("cosmos") | ||
| .UseEmulator() | ||
| .AddDatabase("db"); | ||
|
|
||
| builder.AddProject<Projects.CosmosEndToEnd_ApiService>("api") | ||
| .WithReference(db); | ||
|
|
||
| builder.Build().Run(); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| { | ||
| "$schema": "http://json.schemastore.org/launchsettings.json", | ||
| "profiles": { | ||
| "http": { | ||
| "commandName": "Project", | ||
| "dotnetRunMessages": true, | ||
| "launchBrowser": true, | ||
| "applicationUrl": "http://localhost:15129", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16175" | ||
| } | ||
| }, | ||
| "generate-manifest": { | ||
| "commandName": "Project", | ||
| "launchBrowser": true, | ||
| "dotnetRunMessages": true, | ||
| "commandLineArgs": "--publisher manifest --output-path aspire-manifest.json", | ||
| "applicationUrl": "http://localhost:15129", | ||
| "environmentVariables": { | ||
| "ASPNETCORE_ENVIRONMENT": "Development", | ||
| "DOTNET_ENVIRONMENT": "Development", | ||
| "DOTNET_DASHBOARD_OTLP_ENDPOINT_URL": "http://localhost:16175" | ||
| } | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning" | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "Logging": { | ||
| "LogLevel": { | ||
| "Default": "Information", | ||
| "Microsoft.AspNetCore": "Warning", | ||
| "Aspire.Hosting.Dcp": "Warning" | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <OutputType>Library</OutputType> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| <ImplicitUsings>enable</ImplicitUsings> | ||
| <Nullable>enable</Nullable> | ||
| <IsAspireSharedProject>true</IsAspireSharedProject> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
|
|
||
| <PackageReference Include="Microsoft.Extensions.Http.Resilience" /> | ||
| <PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" /> | ||
| <PackageReference Include="OpenTelemetry.Extensions.Hosting" /> | ||
| <PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" /> | ||
| <PackageReference Include="OpenTelemetry.Instrumentation.GrpcNetClient" /> | ||
| <PackageReference Include="OpenTelemetry.Instrumentation.Http" /> | ||
| <PackageReference Include="OpenTelemetry.Instrumentation.Runtime" /> | ||
|
|
||
| <ProjectReference Include="..\..\..\Microsoft.Extensions.ServiceDiscovery.Dns\Microsoft.Extensions.ServiceDiscovery.Dns.csproj" /> | ||
| <ProjectReference Include="..\..\..\Microsoft.Extensions.ServiceDiscovery\Microsoft.Extensions.ServiceDiscovery.csproj" /> | ||
|
|
||
| </ItemGroup> | ||
|
|
||
| </Project> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should use the word "Playgrounds" and this shouldn't be under the
srcfolder - which is for product code.I'd rather call these "TestProjects", even if they are manual tests.