Skip to content

Commit 106cfb6

Browse files
Copilotdavidfowl
andcommitted
Refactor output path handling to use IPipelineOutputService
- Create IPipelineOutputService interface with GetOutputDirectory() and GetTempDirectory() methods - Implement PipelineOutputService with better naming than IntermediateOutputPath - Expose service via PipelineContext.OutputService and PipelineStepContext.OutputService - Keep backward compatible OutputPath property for existing consumers - Remove direct IntermediateOutputPath property per feedback Co-authored-by: davidfowl <[email protected]>
1 parent e1aa82a commit 106cfb6

File tree

4 files changed

+81
-22
lines changed

4 files changed

+81
-22
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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 System.Diagnostics.CodeAnalysis;
5+
6+
namespace Aspire.Hosting.Pipelines;
7+
8+
/// <summary>
9+
/// Service for managing pipeline output directories.
10+
/// </summary>
11+
[Experimental("ASPIREPIPELINES001", UrlFormat = "https://aka.ms/aspire/diagnostics/{0}")]
12+
public interface IPipelineOutputService
13+
{
14+
/// <summary>
15+
/// Gets the output directory for deployment artifacts.
16+
/// </summary>
17+
/// <returns>The path to the output directory for deployment artifacts.</returns>
18+
string GetOutputDirectory();
19+
20+
/// <summary>
21+
/// Gets a temporary directory for build artifacts.
22+
/// </summary>
23+
/// <returns>The path to a temporary directory for build artifacts.</returns>
24+
string GetTempDirectory();
25+
}

src/Aspire.Hosting/Pipelines/PipelineContext.cs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -53,26 +53,12 @@ public sealed class PipelineContext(
5353
public CancellationToken CancellationToken { get; set; } = cancellationToken;
5454

5555
/// <summary>
56-
/// Gets the output path for deployment artifacts.
56+
/// Gets the service for managing pipeline output directories.
5757
/// </summary>
58-
public string OutputPath { get; } = outputPath ?? Path.Combine(Environment.CurrentDirectory, "aspire-output");
58+
public IPipelineOutputService OutputService { get; } = new PipelineOutputService(outputPath, serviceProvider.GetRequiredService<IConfiguration>());
5959

6060
/// <summary>
61-
/// Gets the intermediate output path for temporary build artifacts.
61+
/// Gets the output path for deployment artifacts.
6262
/// </summary>
63-
public string IntermediateOutputPath { get; } = GetIntermediateOutputPath(serviceProvider);
64-
65-
private static string GetIntermediateOutputPath(IServiceProvider serviceProvider)
66-
{
67-
var configuration = serviceProvider.GetRequiredService<IConfiguration>();
68-
var appHostSha = configuration["AppHost:PathSha256"];
69-
70-
if (!string.IsNullOrEmpty(appHostSha))
71-
{
72-
return Directory.CreateTempSubdirectory($"aspire-{appHostSha}").FullName;
73-
}
74-
75-
// Fallback if AppHost:PathSha256 is not available
76-
return Directory.CreateTempSubdirectory("aspire").FullName;
77-
}
63+
public string OutputPath => OutputService.GetOutputDirectory();
7864
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
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 System.Diagnostics.CodeAnalysis;
5+
using Microsoft.Extensions.Configuration;
6+
7+
namespace Aspire.Hosting.Pipelines;
8+
9+
/// <summary>
10+
/// Default implementation of <see cref="IPipelineOutputService"/>.
11+
/// </summary>
12+
[Experimental("ASPIREPIPELINES001", UrlFormat = "https://aka.ms/aspire/diagnostics/{0}")]
13+
internal sealed class PipelineOutputService : IPipelineOutputService
14+
{
15+
private readonly string? _outputPath;
16+
private readonly Lazy<string> _tempDirectory;
17+
18+
public PipelineOutputService(string? outputPath, IConfiguration configuration)
19+
{
20+
_outputPath = outputPath;
21+
_tempDirectory = new Lazy<string>(() => CreateTempDirectory(configuration));
22+
}
23+
24+
/// <inheritdoc/>
25+
public string GetOutputDirectory()
26+
{
27+
return _outputPath ?? Path.Combine(Environment.CurrentDirectory, "aspire-output");
28+
}
29+
30+
/// <inheritdoc/>
31+
public string GetTempDirectory()
32+
{
33+
return _tempDirectory.Value;
34+
}
35+
36+
private static string CreateTempDirectory(IConfiguration configuration)
37+
{
38+
var appHostSha = configuration["AppHost:PathSha256"];
39+
40+
if (!string.IsNullOrEmpty(appHostSha))
41+
{
42+
return Directory.CreateTempSubdirectory($"aspire-{appHostSha}").FullName;
43+
}
44+
45+
// Fallback if AppHost:PathSha256 is not available
46+
return Directory.CreateTempSubdirectory("aspire").FullName;
47+
}
48+
}

src/Aspire.Hosting/Pipelines/PipelineStepContext.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,12 @@ public sealed class PipelineStepContext
5656
public CancellationToken CancellationToken => PipelineContext.CancellationToken;
5757

5858
/// <summary>
59-
/// Gets the output path for deployment artifacts.
59+
/// Gets the service for managing pipeline output directories.
6060
/// </summary>
61-
public string OutputPath => PipelineContext.OutputPath;
61+
public IPipelineOutputService OutputService => PipelineContext.OutputService;
6262

6363
/// <summary>
64-
/// Gets the intermediate output path for temporary build artifacts.
64+
/// Gets the output path for deployment artifacts.
6565
/// </summary>
66-
public string IntermediateOutputPath => PipelineContext.IntermediateOutputPath;
66+
public string OutputPath => PipelineContext.OutputPath;
6767
}

0 commit comments

Comments
 (0)