diff --git a/src/Umbraco.TestData/Configuration/TestDataSettings.cs b/src/Umbraco.TestData/Configuration/TestDataSettings.cs
new file mode 100644
index 0000000000..78084f726a
--- /dev/null
+++ b/src/Umbraco.TestData/Configuration/TestDataSettings.cs
@@ -0,0 +1,16 @@
+namespace Umbraco.TestData.Configuration
+{
+ public class TestDataSettings
+ {
+ ///
+ /// Gets or sets a value indicating whether the test data generation is enabled.
+ ///
+ public bool Enabled { get; set; } = false;
+
+ ///
+ /// Gets or sets a value indicating whether persisted local database cache files for content and media are disabled.
+ ///
+ /// The URL path.
+ public bool IgnoreLocalDb { get; set; } = false;
+ }
+}
diff --git a/src/Umbraco.TestData/Extensions/UmbracoBuilderExtensions.cs b/src/Umbraco.TestData/Extensions/UmbracoBuilderExtensions.cs
new file mode 100644
index 0000000000..a11e7b12ef
--- /dev/null
+++ b/src/Umbraco.TestData/Extensions/UmbracoBuilderExtensions.cs
@@ -0,0 +1,54 @@
+using System.Linq;
+using Microsoft.AspNetCore.Builder;
+using Microsoft.Extensions.Configuration;
+using Microsoft.Extensions.DependencyInjection;
+using Umbraco.Cms.Core.DependencyInjection;
+using Umbraco.Cms.Infrastructure.PublishedCache;
+using Umbraco.Cms.Web.Common.ApplicationBuilder;
+using Umbraco.TestData.Configuration;
+
+namespace Umbraco.TestData.Extensions
+{
+ public static class UmbracoBuilderExtensions
+ {
+ public static IUmbracoBuilder AddUmbracoTestData(this IUmbracoBuilder builder)
+ {
+ if (builder.Services.Any(x => x.ServiceType == typeof(LoadTestController)))
+ {
+ // We assume forms are composed if any implementations of LoadTestController exists
+ return builder;
+ }
+
+ IConfigurationSection testDataSection = builder.Config.GetSection("Umbraco:CMS:TestData");
+ TestDataSettings config = testDataSection.Get();
+ if (config == null || config.Enabled == false)
+ {
+ return builder;
+ }
+
+ builder.Services.Configure(testDataSection);
+
+ if (config.IgnoreLocalDb)
+ {
+ builder.Services.AddSingleton(factory => new PublishedSnapshotServiceOptions
+ {
+ IgnoreLocalDb = true
+ });
+ }
+
+ builder.Services.Configure(options =>
+ options.AddFilter(new UmbracoPipelineFilter(nameof(LoadTestController))
+ {
+ Endpoints = app => app.UseEndpoints(endpoints =>
+ endpoints.MapControllerRoute(
+ "LoadTest",
+ "/LoadTest/{action}",
+ new { controller = "LoadTest", Action = "Index" }))
+ }));
+
+ builder.Services.AddScoped(typeof(LoadTestController));
+
+ return builder;
+ }
+ }
+}
diff --git a/src/Umbraco.TestData/LoadTestComponent.cs b/src/Umbraco.TestData/LoadTestComponent.cs
deleted file mode 100644
index cfd923cd07..0000000000
--- a/src/Umbraco.TestData/LoadTestComponent.cs
+++ /dev/null
@@ -1,35 +0,0 @@
-using System.Web.Mvc;
-using System.Web.Routing;
-using System.Configuration;
-using Umbraco.Cms.Core.Composing;
-
-// see https://github.com/Shazwazza/UmbracoScripts/tree/master/src/LoadTesting
-
-namespace Umbraco.TestData
-{
- public class LoadTestComponent : IComponent
- {
- public void Initialize()
- {
- if (ConfigurationManager.AppSettings["Umbraco.TestData.Enabled"] != "true")
- return;
-
-
-
- RouteTable.Routes.MapRoute(
- name: "LoadTest",
- url: "LoadTest/{action}",
- defaults: new
- {
- controller = "LoadTest",
- action = "Index"
- },
- namespaces: new[] { "Umbraco.TestData" }
- );
- }
-
- public void Terminate()
- {
- }
- }
-}
diff --git a/src/Umbraco.TestData/LoadTestComposer.cs b/src/Umbraco.TestData/LoadTestComposer.cs
index e5b16e5ab1..8d66c4965d 100644
--- a/src/Umbraco.TestData/LoadTestComposer.cs
+++ b/src/Umbraco.TestData/LoadTestComposer.cs
@@ -1,31 +1,13 @@
-using System.Configuration;
-using Microsoft.Extensions.DependencyInjection;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
-using Umbraco.Cms.Infrastructure.PublishedCache;
+using Umbraco.TestData.Extensions;
// see https://github.com/Shazwazza/UmbracoScripts/tree/master/src/LoadTesting
namespace Umbraco.TestData
{
- public class LoadTestComposer : ComponentComposer, IUserComposer
+ public class LoadTestComposer : IUserComposer
{
- public override void Compose(IUmbracoBuilder builder)
- {
- base.Compose(builder);
-
- if (ConfigurationManager.AppSettings["Umbraco.TestData.Enabled"] != "true")
- return;
-
- builder.Services.AddScoped(typeof(LoadTestController), typeof(LoadTestController));
-
- if (ConfigurationManager.AppSettings["Umbraco.TestData.IgnoreLocalDb"] == "true")
- {
- builder.Services.AddSingleton(factory => new PublishedSnapshotServiceOptions
- {
- IgnoreLocalDb = true
- });
- }
- }
+ public void Compose(IUmbracoBuilder builder) => builder.AddUmbracoTestData();
}
}
diff --git a/src/Umbraco.TestData/LoadTestController.cs b/src/Umbraco.TestData/LoadTestController.cs
index e1494fbdab..3033d2febb 100644
--- a/src/Umbraco.TestData/LoadTestController.cs
+++ b/src/Umbraco.TestData/LoadTestController.cs
@@ -1,21 +1,15 @@
-using System;
-using System.Configuration;
+using System;
using System.Diagnostics;
+using System.IO;
using System.Linq;
+using System.Text;
using System.Threading;
-using System.Web;
-using System.Web.Hosting;
-using System.Web.Mvc;
-using System.Web.Routing;
-using Microsoft.Extensions.DependencyInjection;
-using Umbraco.Cms.Core.Composing;
-using Umbraco.Cms.Core.DependencyInjection;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.Extensions.Hosting;
+using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Strings;
-using System.IO;
-using Umbraco.Cms.Core;
-using Umbraco.Cms.Core.Hosting;
// see https://github.com/Shazwazza/UmbracoScripts/tree/master/src/LoadTesting
@@ -23,27 +17,17 @@ namespace Umbraco.TestData
{
public class LoadTestController : Controller
{
- public LoadTestController(
- ServiceContext serviceContext,
- IShortStringHelper shortStringHelper,
- IHostingEnvironment hostingEnvironment)
- {
- _serviceContext = serviceContext;
- _shortStringHelper = shortStringHelper;
- _hostingEnvironment = hostingEnvironment;
- }
+ private static readonly Random s_random = new Random();
+ private static readonly object s_locko = new object();
- private static readonly Random _random = new Random();
- private static readonly object _locko = new object();
+ private static volatile int s_containerId = -1;
- private static volatile int _containerId = -1;
+ private const string ContainerAlias = "LoadTestContainer";
+ private const string ContentAlias = "LoadTestContent";
+ private const int TextboxDefinitionId = -88;
+ private const int MaxCreate = 1000;
- private const string _containerAlias = "LoadTestContainer";
- private const string _contentAlias = "LoadTestContent";
- private const int _textboxDefinitionId = -88;
- private const int _maxCreate = 1000;
-
- private static readonly string HeadHtml = @"
+ private static readonly string s_headHtml = @"
LoadTest