Skip to content

Commit a481f66

Browse files
Copilotdavidfowl
andcommitted
Remove OutputService from PipelineContext and resolve from DI
- Register IPipelineOutputService in DI container with PipelineOptions - Remove OutputService property from PipelineContext and PipelineStepContext - Remove outputPath parameter from PipelineContext constructor - Update all consumers to resolve IPipelineOutputService from Services - AzureEnvironmentResource - PublishingContextUtils - JsonDocumentManifestPublisher test helper - Remove IOptions<PipelineOptions> dependency from PipelineExecutor - Steps now explicitly resolve IPipelineOutputService when needed Co-authored-by: davidfowl <[email protected]>
1 parent a650bd9 commit a481f66

File tree

8 files changed

+19
-25
lines changed

8 files changed

+19
-25
lines changed

src/Aspire.Hosting.Azure/AzureEnvironmentResource.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,9 @@ public AzureEnvironmentResource(string name, ParameterResource location, Paramet
121121
private Task PublishAsync(PipelineStepContext context)
122122
{
123123
var azureProvisioningOptions = context.Services.GetRequiredService<IOptions<AzureProvisioningOptions>>();
124+
var outputService = context.Services.GetRequiredService<IPipelineOutputService>();
124125
var publishingContext = new AzurePublishingContext(
125-
context.OutputService.GetOutputDirectory(),
126+
outputService.GetOutputDirectory(),
126127
azureProvisioningOptions.Value,
127128
context.Services,
128129
context.Logger,

src/Aspire.Hosting/DistributedApplicationBuilder.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,13 @@ public DistributedApplicationBuilder(DistributedApplicationOptions options)
462462
_innerBuilder.Services.AddSingleton<IResourceContainerImageBuilder, ResourceContainerImageBuilder>();
463463
_innerBuilder.Services.AddSingleton<PipelineActivityReporter>();
464464
_innerBuilder.Services.AddSingleton<IPipelineActivityReporter, PipelineActivityReporter>(sp => sp.GetRequiredService<PipelineActivityReporter>());
465+
_innerBuilder.Services.AddSingleton<IPipelineOutputService>(sp =>
466+
{
467+
var options = sp.GetRequiredService<IOptions<PipelineOptions>>();
468+
var configuration = sp.GetRequiredService<IConfiguration>();
469+
var outputPath = options.Value.OutputPath is not null ? Path.GetFullPath(options.Value.OutputPath) : null;
470+
return new PipelineOutputService(outputPath, configuration);
471+
});
465472
_innerBuilder.Services.AddSingleton(Pipeline);
466473

467474
// Configure pipeline logging options

src/Aspire.Hosting/Pipelines/PipelineContext.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33

44
using System.Diagnostics.CodeAnalysis;
55
using Aspire.Hosting.ApplicationModel;
6-
using Microsoft.Extensions.Configuration;
7-
using Microsoft.Extensions.DependencyInjection;
86
using Microsoft.Extensions.Logging;
97

108
namespace Aspire.Hosting.Pipelines;
@@ -17,15 +15,13 @@ namespace Aspire.Hosting.Pipelines;
1715
/// <param name="serviceProvider">The service provider for dependency resolution.</param>
1816
/// <param name="logger">The logger for pipeline operations.</param>
1917
/// <param name="cancellationToken">The cancellation token for the pipeline operation.</param>
20-
/// <param name="outputPath">The output path for deployment artifacts.</param>
2118
[Experimental("ASPIREPIPELINES001", UrlFormat = "https://aka.ms/aspire/diagnostics/{0}")]
2219
public sealed class PipelineContext(
2320
DistributedApplicationModel model,
2421
DistributedApplicationExecutionContext executionContext,
2522
IServiceProvider serviceProvider,
2623
ILogger logger,
27-
CancellationToken cancellationToken,
28-
string? outputPath)
24+
CancellationToken cancellationToken)
2925
{
3026
/// <summary>
3127
/// Gets the distributed application model to be deployed.
@@ -51,9 +47,4 @@ public sealed class PipelineContext(
5147
/// Gets the cancellation token for the pipeline operation.
5248
/// </summary>
5349
public CancellationToken CancellationToken { get; set; } = cancellationToken;
54-
55-
/// <summary>
56-
/// Gets the service for managing pipeline output directories.
57-
/// </summary>
58-
public IPipelineOutputService OutputService { get; } = new PipelineOutputService(outputPath, serviceProvider.GetRequiredService<IConfiguration>());
5950
}

src/Aspire.Hosting/Pipelines/PipelineStepContext.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,4 @@ public sealed class PipelineStepContext
5454
/// Gets the cancellation token for the pipeline operation.
5555
/// </summary>
5656
public CancellationToken CancellationToken => PipelineContext.CancellationToken;
57-
58-
/// <summary>
59-
/// Gets the service for managing pipeline output directories.
60-
/// </summary>
61-
public IPipelineOutputService OutputService => PipelineContext.OutputService;
6257
}

src/Aspire.Hosting/Publishing/PipelineExecutor.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
using Microsoft.Extensions.DependencyInjection;
1313
using Microsoft.Extensions.Hosting;
1414
using Microsoft.Extensions.Logging;
15-
using Microsoft.Extensions.Options;
1615

1716
namespace Aspire.Hosting.Publishing;
1817

@@ -25,7 +24,6 @@ internal sealed class PipelineExecutor(
2524
IPipelineActivityReporter activityReporter,
2625
IDistributedApplicationEventing eventing,
2726
BackchannelService backchannelService,
28-
IOptions<PipelineOptions> options,
2927
IPipelineActivityReporter pipelineActivityReporter) : BackgroundService
3028
{
3129
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
@@ -99,8 +97,7 @@ await eventing.PublishAsync<AfterPublishEvent>(
9997

10098
public async Task ExecutePipelineAsync(DistributedApplicationModel model, CancellationToken cancellationToken)
10199
{
102-
var pipelineContext = new PipelineContext(model, executionContext, serviceProvider, logger, cancellationToken, options.Value.OutputPath is not null ?
103-
Path.GetFullPath(options.Value.OutputPath) : null);
100+
var pipelineContext = new PipelineContext(model, executionContext, serviceProvider, logger, cancellationToken);
104101

105102
var pipeline = serviceProvider.GetRequiredService<IDistributedApplicationPipeline>();
106103
await pipeline.ExecuteAsync(pipelineContext).ConfigureAwait(false);

src/Shared/PublishingContextUtils.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,23 @@
55

66
using Aspire.Hosting.ApplicationModel;
77
using Aspire.Hosting.Pipelines;
8+
using Microsoft.Extensions.DependencyInjection;
89

910
namespace Aspire.Hosting.Utils;
1011

1112
internal static class PublishingContextUtils
1213
{
1314
public static string GetEnvironmentOutputPath(PipelineStepContext context, IComputeEnvironmentResource environment)
1415
{
16+
var outputService = context.Services.GetRequiredService<IPipelineOutputService>();
17+
1518
if (context.Model.Resources.OfType<IComputeEnvironmentResource>().Count() > 1)
1619
{
1720
// If there are multiple compute environments, append the environment name to the output path
18-
return Path.Combine(context.OutputService.GetOutputDirectory(), environment.Name);
21+
return Path.Combine(outputService.GetOutputDirectory(), environment.Name);
1922
}
2023

2124
// If there is only one compute environment, use the root output path
22-
return context.OutputService.GetOutputDirectory();
25+
return outputService.GetOutputDirectory();
2326
}
2427
}

tests/Aspire.Hosting.Tests/Helpers/JsonDocumentManifestPublisher.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ public static IDistributedApplicationPipeline AddJsonDocumentManifestPublishing(
7878
using var stream = new MemoryStream();
7979
using var writer = new Utf8JsonWriter(stream, new() { Indented = true });
8080

81-
var manifestPath = context.OutputService.GetOutputDirectory();
81+
var outputService = context.Services.GetRequiredService<IPipelineOutputService>();
82+
var manifestPath = outputService.GetOutputDirectory();
8283
var publishingContext = new ManifestPublishingContext(executionContext, manifestPath, writer, context.CancellationToken);
8384

8485
await publishingContext.WriteModel(context.Model, context.CancellationToken).ConfigureAwait(false);

tests/Aspire.Hosting.Tests/Pipelines/DistributedApplicationPipelineTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,8 +876,7 @@ private static PipelineContext CreateDeployingContext(DistributedApplication app
876876
app.Services.GetRequiredService<DistributedApplicationExecutionContext>(),
877877
app.Services,
878878
NullLogger.Instance,
879-
CancellationToken.None,
880-
outputPath: null);
879+
CancellationToken.None);
881880
}
882881

883882
[Fact]

0 commit comments

Comments
 (0)