diff --git a/Aspire.sln b/Aspire.sln index 19051baa4d1..7972b48f7b1 100644 --- a/Aspire.sln +++ b/Aspire.sln @@ -635,11 +635,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AzureContainerApps.ApiServi EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Aspire.ProjectTemplates", "src\Aspire.ProjectTemplates\Aspire.ProjectTemplates.csproj", "{D07A8344-C61A-478A-92F0-E9B2DA00D647}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WaitFor.Frontend", "playground\waitfor\WaitFor.Frontend\WaitFor.Frontend.csproj", "{C88BBF0B-7566-48BD-A2BC-05374B1A2B22}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "WaitFor.Frontend", "playground\waitfor\WaitFor.Frontend\WaitFor.Frontend.csproj", "{C88BBF0B-7566-48BD-A2BC-05374B1A2B22}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "HealthChecks", "HealthChecks", "{B7345F72-712F-436C-AE18-CAF7CDD4A990}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HealthChecksSandbox.AppHost", "playground\HealthChecks\HealthChecksSandbox.AppHost\HealthChecksSandbox.AppHost.csproj", "{042DD8C6-A26C-4B06-80A1-FE7F8659C5BC}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HealthChecksSandbox.AppHost", "playground\HealthChecks\HealthChecksSandbox.AppHost\HealthChecksSandbox.AppHost.csproj", "{042DD8C6-A26C-4B06-80A1-FE7F8659C5BC}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DaprServiceC", "playground\dapr\ServiceC\DaprServiceC.csproj", "{B26653B9-439E-4850-A7F8-43C6E5121952}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -1683,6 +1685,10 @@ Global {042DD8C6-A26C-4B06-80A1-FE7F8659C5BC}.Debug|Any CPU.Build.0 = Debug|Any CPU {042DD8C6-A26C-4B06-80A1-FE7F8659C5BC}.Release|Any CPU.ActiveCfg = Release|Any CPU {042DD8C6-A26C-4B06-80A1-FE7F8659C5BC}.Release|Any CPU.Build.0 = Release|Any CPU + {B26653B9-439E-4850-A7F8-43C6E5121952}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B26653B9-439E-4850-A7F8-43C6E5121952}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B26653B9-439E-4850-A7F8-43C6E5121952}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B26653B9-439E-4850-A7F8-43C6E5121952}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -1991,6 +1997,7 @@ Global {C88BBF0B-7566-48BD-A2BC-05374B1A2B22} = {3FF3F00C-95C0-46FC-B2BE-A3920C71E393} {B7345F72-712F-436C-AE18-CAF7CDD4A990} = {D173887B-AF42-4576-B9C1-96B9E9B3D9C0} {042DD8C6-A26C-4B06-80A1-FE7F8659C5BC} = {B7345F72-712F-436C-AE18-CAF7CDD4A990} + {B26653B9-439E-4850-A7F8-43C6E5121952} = {57A42144-739E-49A7-BADB-BB8F5F20FA17} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {6DCEDFEC-988E-4CB3-B45B-191EB5086E0C} diff --git a/Directory.Packages.props b/Directory.Packages.props index ddc8a6da1d1..7b6311aae2f 100644 --- a/Directory.Packages.props +++ b/Directory.Packages.props @@ -96,7 +96,7 @@ - + @@ -189,11 +189,10 @@ - + - @@ -202,4 +201,4 @@ - + \ No newline at end of file diff --git a/playground/Directory.Packages.props b/playground/Directory.Packages.props index ebc3670efb4..abdaeaf7ab0 100644 --- a/playground/Directory.Packages.props +++ b/playground/Directory.Packages.props @@ -1,5 +1,7 @@ - - + + + + \ No newline at end of file diff --git a/playground/dapr/Dapr.AppHost/Dapr.AppHost.csproj b/playground/dapr/Dapr.AppHost/Dapr.AppHost.csproj index 63a9cb3244d..1e2b1f25293 100644 --- a/playground/dapr/Dapr.AppHost/Dapr.AppHost.csproj +++ b/playground/dapr/Dapr.AppHost/Dapr.AppHost.csproj @@ -19,6 +19,7 @@ + diff --git a/playground/dapr/Dapr.AppHost/Program.cs b/playground/dapr/Dapr.AppHost/Program.cs index dbdf6838095..24fb6d9b621 100644 --- a/playground/dapr/Dapr.AppHost/Program.cs +++ b/playground/dapr/Dapr.AppHost/Program.cs @@ -18,6 +18,11 @@ .WithDaprSidecar() .WithReference(pubSub); +// console app with no appPort (sender only) +builder.AddProject("servicec") + .WithReference(stateStore) + .WithDaprSidecar(); + #if !SKIP_DASHBOARD_REFERENCE // 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 diff --git a/playground/dapr/ServiceC/DaprServiceC.csproj b/playground/dapr/ServiceC/DaprServiceC.csproj new file mode 100644 index 00000000000..9b35e4db9ef --- /dev/null +++ b/playground/dapr/ServiceC/DaprServiceC.csproj @@ -0,0 +1,15 @@ + + + + Exe + net8.0 + enable + enable + + + + + + + + diff --git a/playground/dapr/ServiceC/Program.cs b/playground/dapr/ServiceC/Program.cs new file mode 100644 index 00000000000..c5f641494c0 --- /dev/null +++ b/playground/dapr/ServiceC/Program.cs @@ -0,0 +1,41 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using Dapr.Client; +using Test; + +var builder = Host.CreateApplicationBuilder(args); + +var dapr = new DaprClientBuilder() + .Build(); + +builder.Services.AddSingleton(dapr); + +builder.Services.AddHostedService(); + +var app = builder.Build(); + +await app.RunAsync(); + +Console.WriteLine("Goodbye, World!"); + +namespace Test +{ + public sealed class Worker(ILogger logger, DaprClient dapr) : BackgroundService + { + protected override async Task ExecuteAsync(CancellationToken stoppingToken) + { + await dapr.WaitForSidecarAsync(stoppingToken); + + while (!stoppingToken.IsCancellationRequested) + { + var state = await dapr.GetStateAsync( + "statestore", "cache", cancellationToken: stoppingToken); + + logger.LogInformation("State: {0}", state ?? ""); + + await Task.Delay(1000, stoppingToken); + } + } + } +} diff --git a/src/Aspire.Hosting.Dapr/DaprDistributedApplicationLifecycleHook.cs b/src/Aspire.Hosting.Dapr/DaprDistributedApplicationLifecycleHook.cs index 087e2a1b51f..417a4a7cda3 100644 --- a/src/Aspire.Hosting.Dapr/DaprDistributedApplicationLifecycleHook.cs +++ b/src/Aspire.Hosting.Dapr/DaprDistributedApplicationLifecycleHook.cs @@ -190,12 +190,10 @@ public async Task BeforeStartAsync(DistributedApplicationModel appModel, Cancell { updatedArgs.AddRange(daprCommandLine.Arguments); var endPoint = GetEndpointReference(sidecarOptions, resource); - if (endPoint is not null) + + if (sidecarOptions?.AppPort is null && endPoint is { appEndpoint.IsAllocated: true }) { - if (endPoint.Value.appEndpoint.IsAllocated && sidecarOptions?.AppPort is null) - { - updatedArgs.AddRange(daprAppPortArg(endPoint.Value.appEndpoint.Port)()); - } + updatedArgs.AddRange(daprAppPortArg(endPoint.Value.appEndpoint.Port)()); } var grpc = daprCli.GetEndpoint("grpc"); @@ -213,11 +211,11 @@ public async Task BeforeStartAsync(DistributedApplicationModel appModel, Cancell updatedArgs.AddRange(daprProfilePortArg(profiling.Property(EndpointProperty.TargetPort))()); } - if (sidecarOptions?.AppChannelAddress is null && endPoint is not null) + if (sidecarOptions?.AppChannelAddress is null && endPoint is { appEndpoint.IsAllocated: true }) { updatedArgs.AddRange(daprAppChannelAddressArg(endPoint.Value.appEndpoint.Host)()); } - if (sidecarOptions?.AppProtocol is null && endPoint is not null) + if (sidecarOptions?.AppProtocol is null && endPoint is { appEndpoint.IsAllocated: true }) { updatedArgs.AddRange(daprAppProtocol(endPoint.Value.protocol)()); }