From 84d8de1d5c9eba00a4b66365b1fae91b391e32e7 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Mon, 29 Jan 2024 20:30:02 +1100 Subject: [PATCH 1/2] Fix precondition in DcpHostService Two lines are changed here, though it's the second (in `StopAsync`) that has a functional change. The first guard clause allows a null publisher, or a "dcp" publisher. The second clause would allow any non-null publisher, which looks like a bug to me. Specifically, the first half of the || excludes "dcp", then the second half allows it back in. This means that there's no point checking for "dcp" in the code as written. My interpretation of this code is that both clauses are intended to be the same, and this commit brings them in line with one another. --- src/Aspire.Hosting/Dcp/DcpHostService.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Aspire.Hosting/Dcp/DcpHostService.cs b/src/Aspire.Hosting/Dcp/DcpHostService.cs index d034834f894..c32d162067a 100644 --- a/src/Aspire.Hosting/Dcp/DcpHostService.cs +++ b/src/Aspire.Hosting/Dcp/DcpHostService.cs @@ -51,7 +51,7 @@ public DcpHostService( public async Task StartAsync(CancellationToken cancellationToken = default) { - if (_publishingOptions.Publisher is not null && _publishingOptions.Publisher != "dcp") + if (_publishingOptions.Publisher is not null and not "dcp") { return; } @@ -67,7 +67,7 @@ public async Task StartAsync(CancellationToken cancellationToken = default) public async Task StopAsync(CancellationToken cancellationToken = default) { - if (_publishingOptions.Publisher != "dcp" || _publishingOptions.Publisher is not null) + if (_publishingOptions.Publisher is not null and not "dcp") { return; } From 5044827237d5995cf297dac8c4e96f36a3295b5b Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Tue, 30 Jan 2024 12:56:34 +1100 Subject: [PATCH 2/2] Deduplicate condition --- src/Aspire.Hosting/Dcp/DcpHostService.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Aspire.Hosting/Dcp/DcpHostService.cs b/src/Aspire.Hosting/Dcp/DcpHostService.cs index c32d162067a..334a32eccaa 100644 --- a/src/Aspire.Hosting/Dcp/DcpHostService.cs +++ b/src/Aspire.Hosting/Dcp/DcpHostService.cs @@ -49,9 +49,11 @@ public DcpHostService( _locations = locations; } + private bool IsSupported => _publishingOptions.Publisher is null or "dcp"; + public async Task StartAsync(CancellationToken cancellationToken = default) { - if (_publishingOptions.Publisher is not null and not "dcp") + if (!IsSupported) { return; } @@ -67,7 +69,7 @@ public async Task StartAsync(CancellationToken cancellationToken = default) public async Task StopAsync(CancellationToken cancellationToken = default) { - if (_publishingOptions.Publisher is not null and not "dcp") + if (!IsSupported) { return; }