2020-12-23 11:35:49 +01:00
|
|
|
// Copyright (c) Umbraco.
|
|
|
|
|
// See LICENSE for more details.
|
|
|
|
|
|
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
2020-03-30 20:55:13 +11:00
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
2020-03-31 18:01:27 +11:00
|
|
|
using Microsoft.Extensions.Hosting;
|
2021-02-18 11:06:02 +01:00
|
|
|
using Umbraco.Cms.Tests.Integration.Implementations;
|
2020-03-30 20:55:13 +11:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
namespace Umbraco.Cms.Tests.Integration.Extensions;
|
|
|
|
|
|
|
|
|
|
public static class ServiceCollectionExtensions
|
2020-03-30 20:55:13 +11:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
/// <summary>
|
|
|
|
|
/// These services need to be manually added because they do not get added by the generic host
|
|
|
|
|
/// </summary>
|
|
|
|
|
public static void AddRequiredNetCoreServices(this IServiceCollection services, TestHelper testHelper, IWebHostEnvironment webHostEnvironment)
|
2020-03-30 20:55:13 +11:00
|
|
|
{
|
2022-06-21 08:09:38 +02:00
|
|
|
services.AddSingleton(x => testHelper.GetHttpContextAccessor());
|
2020-12-23 11:35:49 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
// The generic host does add IHostEnvironment but not this one because we are not actually in a web context
|
|
|
|
|
services.AddSingleton(x => webHostEnvironment);
|
2020-12-23 11:35:49 +01:00
|
|
|
|
2022-06-21 08:09:38 +02:00
|
|
|
// Replace the IHostEnvironment that generic host created too
|
|
|
|
|
services.AddSingleton<IHostEnvironment>(x => webHostEnvironment);
|
2020-03-30 20:55:13 +11:00
|
|
|
}
|
|
|
|
|
}
|