2024-07-04 11:02:45 +05:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2023-02-22 15:00:43 +05:00
|
|
|
using System.Linq;
|
|
|
|
|
2024-08-19 10:57:31 +05:00
|
|
|
namespace AsbCloudInfrastructure.Tests;
|
2024-08-19 10:01:07 +05:00
|
|
|
|
|
|
|
public static class AspExtensions
|
2023-02-22 15:00:43 +05:00
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
public static IServiceCollection ReplaceService<T>(this IServiceCollection services, T instance)
|
|
|
|
where T : notnull
|
2023-02-22 15:00:43 +05:00
|
|
|
{
|
2024-08-19 10:01:07 +05:00
|
|
|
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;
|
2023-02-22 15:00:43 +05:00
|
|
|
}
|
|
|
|
}
|