forked from ddrilling/AsbCloudServer
19 lines
563 B
C#
19 lines
563 B
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using System.Linq;
|
|
|
|
namespace AsbCloudWebApi.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;
|
|
}
|
|
}
|