DD.WellWorkover.Cloud/AsbCloudInfrastructure.Tests/AspExtensions.cs
2024-08-19 10:57:31 +05:00

19 lines
571 B
C#

using Microsoft.Extensions.DependencyInjection;
using System.Linq;
namespace AsbCloudInfrastructure.Tests;
public static class AspExtensions
{
public static IServiceCollection ReplaceService<T>(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;
}
}