Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions src/Aspire.Cli/AppHostRunning/AppHostRunnerContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Aspire.Cli.AppHostRunning;

/// <summary>
/// Context information for creating an AppHost runner.
/// </summary>
internal sealed class AppHostRunnerContext
{
/// <summary>
/// Initializes a new instance of the <see cref="AppHostRunnerContext"/> class.
/// </summary>
/// <param name="appHostFile">The AppHost file to run.</param>
/// <param name="settingsFile">The settings file associated with the AppHost, if it exists.</param>
public AppHostRunnerContext(FileInfo appHostFile, FileInfo? settingsFile = null)
{
ArgumentNullException.ThrowIfNull(appHostFile);

AppHostFile = appHostFile;
SettingsFile = settingsFile;
}

/// <summary>
/// Gets the AppHost file to run.
/// </summary>
public FileInfo AppHostFile { get; }

/// <summary>
/// Gets the settings file associated with the AppHost, if it exists.
/// </summary>
public FileInfo? SettingsFile { get; }
}
74 changes: 74 additions & 0 deletions src/Aspire.Cli/AppHostRunning/AppHostRunnerFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Aspire.Cli.Certificates;
using Aspire.Cli.Configuration;
using Aspire.Cli.DotNet;
using Aspire.Cli.Interaction;
using Aspire.Cli.Telemetry;
using Microsoft.Extensions.Configuration;

namespace Aspire.Cli.AppHostRunning;

/// <summary>
/// Factory for creating AppHost runners.
/// </summary>
internal sealed class AppHostRunnerFactory : IAppHostRunnerFactory
{
private readonly IDotNetCliRunner _runner;
private readonly IInteractionService _interactionService;
private readonly ICertificateService _certificateService;
private readonly Spectre.Console.IAnsiConsole _ansiConsole;
private readonly AspireCliTelemetry _telemetry;
private readonly IConfiguration _configuration;
private readonly IFeatures _features;
private readonly CliExecutionContext _executionContext;

public AppHostRunnerFactory(
IDotNetCliRunner runner,
IInteractionService interactionService,
ICertificateService certificateService,
Spectre.Console.IAnsiConsole ansiConsole,
AspireCliTelemetry telemetry,
IConfiguration configuration,
IFeatures features,
CliExecutionContext executionContext)
{
ArgumentNullException.ThrowIfNull(runner);
ArgumentNullException.ThrowIfNull(interactionService);
ArgumentNullException.ThrowIfNull(certificateService);
ArgumentNullException.ThrowIfNull(ansiConsole);
ArgumentNullException.ThrowIfNull(telemetry);
ArgumentNullException.ThrowIfNull(configuration);
ArgumentNullException.ThrowIfNull(features);
ArgumentNullException.ThrowIfNull(executionContext);

_runner = runner;
_interactionService = interactionService;
_certificateService = certificateService;
_ansiConsole = ansiConsole;
_telemetry = telemetry;
_configuration = configuration;
_features = features;
_executionContext = executionContext;
}

public IAppHostRunner CreateRunner(AppHostRunnerContext context)
{
ArgumentNullException.ThrowIfNull(context);

// For now, we only have one type of runner - the legacy .NET-based runner
// In the future, we can add logic here to determine the appropriate runner
// based on the file type or other characteristics
return new LegacyAppHostRunner(
context.AppHostFile,
_runner,
_interactionService,
_certificateService,
_ansiConsole,
_telemetry,
_configuration,
_features,
_executionContext);
}
}
20 changes: 20 additions & 0 deletions src/Aspire.Cli/AppHostRunning/IAppHostRunner.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.CommandLine;

namespace Aspire.Cli.AppHostRunning;

/// <summary>
/// Defines the contract for running an AppHost.
/// </summary>
internal interface IAppHostRunner
{
/// <summary>
/// Runs the AppHost asynchronously.
/// </summary>
/// <param name="parseResult">The parsed command line arguments.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>The exit code from running the AppHost.</returns>
Task<int> RunAsync(ParseResult parseResult, CancellationToken cancellationToken);
}
17 changes: 17 additions & 0 deletions src/Aspire.Cli/AppHostRunning/IAppHostRunnerFactory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Aspire.Cli.AppHostRunning;

/// <summary>
/// Factory for creating AppHost runners based on the AppHost file type.
/// </summary>
internal interface IAppHostRunnerFactory
{
/// <summary>
/// Creates an appropriate runner for the given AppHost context.
/// </summary>
/// <param name="context">The context containing the AppHost file and related information.</param>
/// <returns>An instance of <see cref="IAppHostRunner"/> capable of running the specified AppHost.</returns>
IAppHostRunner CreateRunner(AppHostRunnerContext context);
}
Loading
Loading