forked from ddrilling/AsbCloudServer
20 lines
620 B
C#
20 lines
620 B
C#
|
using Microsoft.Extensions.DependencyInjection;
|
|||
|
using System.Linq;
|
|||
|
|
|||
|
namespace AsbCloudWebApi.Tests
|
|||
|
{
|
|||
|
public static class AspExtentions
|
|||
|
{
|
|||
|
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;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|