From 0e4518f6fb75e71a36f391fbc7ba4826335d3ccd Mon Sep 17 00:00:00 2001 From: Martin Costello Date: Tue, 9 Sep 2025 17:48:28 +0100 Subject: [PATCH] [Resources.AWS] Replace IWebHost with IHost Replace usage of `IWebHost` with `IHost`, which is marked as obsolete in .NET 10. --- .../AWSECSDetectorTests.cs | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/test/OpenTelemetry.Resources.AWS.Tests/AWSECSDetectorTests.cs b/test/OpenTelemetry.Resources.AWS.Tests/AWSECSDetectorTests.cs index 1e43be5587..40980ec2f0 100644 --- a/test/OpenTelemetry.Resources.AWS.Tests/AWSECSDetectorTests.cs +++ b/test/OpenTelemetry.Resources.AWS.Tests/AWSECSDetectorTests.cs @@ -6,8 +6,11 @@ using System.Text; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting.Server; using Microsoft.AspNetCore.Hosting.Server.Features; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using Xunit; namespace OpenTelemetry.Resources.AWS.Tests; @@ -143,11 +146,12 @@ internal void ResetEnvironment() internal class MockEcsMetadataEndpoint : IAsyncDisposable { public readonly Uri Address; - private readonly IWebHost server; + private readonly IHost host; public MockEcsMetadataEndpoint(string containerJsonPath, string taskJsonPath) { - this.server = new WebHostBuilder() + this.host = new HostBuilder() + .ConfigureWebHost(builder => builder .UseKestrel() .UseUrls("http://127.0.0.1:0") // Use random localhost port .Configure(app => @@ -174,21 +178,18 @@ public MockEcsMetadataEndpoint(string containerJsonPath, string taskJsonPath) await context.Response.WriteAsync("Not found"); } }); - }).Build(); - this.server.Start(); + })).Build(); + this.host.Start(); - this.Address = new Uri(this.server.ServerFeatures.Get()!.Addresses.First()); + var server = this.host.Services.GetRequiredService(); + this.Address = new Uri(server.Features.Get()!.Addresses.First()); } - public async ValueTask DisposeAsync() - { + public async ValueTask DisposeAsync() => await this.DisposeAsyncCore(); - } - protected virtual async ValueTask DisposeAsyncCore() - { - await this.server.StopAsync(); - } + protected virtual async ValueTask DisposeAsyncCore() => + await this.host.StopAsync(); } private static class ExpectedSemanticConventions