using Microsoft.Extensions.DependencyInjection; using System.Linq; namespace AsbCloudWebApi.Tests; public static class AspExtensions { public static IServiceCollection ReplaceService(this IServiceCollection services, T instance) where T : notnull { var typeofT = typeof(T); var originalDecriptor = services.Last(s => s.ServiceType == typeofT); var newDecriptor = new ServiceDescriptor(typeofT, instance); services.Remove(originalDecriptor); services.Add(newDecriptor); return services; } }