Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pr: 1884
changes:
- section: "Other Changes"
description: "AppLens: Improve testability by removing dependency on CommandContext.ServiceProvider in ExecuteAsync"
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ namespace Azure.Mcp.Tools.AppLens.Commands.Resource;
/// <summary>
/// Command to diagnose Azure resources using AppLens conversational diagnostics.
/// </summary>
public sealed class ResourceDiagnoseCommand(ILogger<ResourceDiagnoseCommand> logger)
public sealed class ResourceDiagnoseCommand(ILogger<ResourceDiagnoseCommand> logger, IAppLensService appLensService)
: SubscriptionCommand<ResourceDiagnoseOptions>
{
private const string CommandTitle = "Diagnose Azure Resource Issues";
private readonly ILogger<ResourceDiagnoseCommand> _logger = logger;
private readonly IAppLensService _appLensService = appLensService;

public override string Id => "92fb5b7d-f1d7-4834-a61a-e170ad8594ac";

Expand Down Expand Up @@ -73,12 +74,10 @@ public override async Task<CommandResponse> ExecuteAsync(CommandContext context,

ResourceDiagnoseOptions options = BindOptions(parseResult);

var service = context.GetService<IAppLensService>();

_logger.LogInformation("Diagnosing resource. Question: {Question}, Resource: {Resource}, Options: {Options}",
options.Question, options.Resource, options);

var result = await service.DiagnoseResourceAsync(
var result = await _appLensService.DiagnoseResourceAsync(
options.Question,
options.Resource,
options.Subscription!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ public ResourceDiagnoseCommandTests()
_appLensService = Substitute.For<IAppLensService>();
_logger = Substitute.For<ILogger<ResourceDiagnoseCommand>>();

_command = new(_logger);
_command = new(_logger, _appLensService);
_serviceProvider = new ServiceCollection()
.AddSingleton(_appLensService)
.BuildServiceProvider();
_context = new(_serviceProvider);
}
Expand Down
Loading