Ensure proper disposal and add HttpExtensions class

Updated `InvokeRecActionCommand.cs` to use `using` statements for `HttpClient`, `HttpRequestMessage`, and `HttpResponseMessage` to prevent resource leaks.

Added a new `HttpExtensions.cs` file with a static `HttpExtensions` class as a placeholder for future HTTP-related extension methods. Included necessary `using` directives for potential LINQ, collections, and asynchronous programming.
This commit is contained in:
tekh 2025-11-27 11:32:14 +01:00
parent 2f3a685e7d
commit a46d97467d
2 changed files with 14 additions and 5 deletions

View File

@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ReC.Application.Common;
public static class HttpExtensions
{
}

View File

@ -1,8 +1,6 @@
using MediatR;
using Microsoft.Extensions.Logging;
using ReC.Application.Common.Dto;
using System;
using static System.Net.WebRequestMethods;
namespace ReC.Application.RecActions.Commands;
@ -25,7 +23,7 @@ public class InvokeRecActionCommandHandler(
{
public async Task Handle(InvokeRecActionCommand request, CancellationToken cancel)
{
var http = clientFactory.CreateClient();
using var http = clientFactory.CreateClient();
if (request.RestType is null)
{
@ -38,9 +36,9 @@ public class InvokeRecActionCommandHandler(
}
var method = new HttpMethod(request.RestType.ToUpper());
var msg = new HttpRequestMessage(method, request.EndpointUri);
using var msg = new HttpRequestMessage(method, request.EndpointUri);
var response = await http.SendAsync(msg, cancel);
using var response = await http.SendAsync(msg, cancel);
var body = await response.Content.ReadAsStringAsync(cancel);
var headers = response.Headers.ToDictionary();
}