<commit_before>using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Hosting;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Hosting;
using Umbraco.Core.IO;
using IRegisteredObject = Umbraco.Core.IRegisteredObject;

namespace Umbraco.Web.Hosting
{
    public class AspNetHostingEnvironment : IHostingEnvironment
    {
        private readonly IHostingSettings _hostingSettings;
        private string _localTempPath;

        public AspNetHostingEnvironment(IHostingSettings hostingSettings)
        {
            _hostingSettings = hostingSettings ?? throw new ArgumentNullException(nameof(hostingSettings));
            SiteName = HostingEnvironment.SiteName;
            ApplicationId = HostingEnvironment.ApplicationID;
            ApplicationPhysicalPath = HostingEnvironment.ApplicationPhysicalPath;
            ApplicationVirtualPath = HostingEnvironment.ApplicationVirtualPath;
            CurrentDomainId = AppDomain.CurrentDomain.Id;
        }

        public int CurrentDomainId { get; }

        public string SiteName { get; }
        public string ApplicationId { get; }
        public string ApplicationPhysicalPath { get; }

        public string ApplicationVirtualPath { get; }
        public bool IsDebugMode => HttpContext.Current?.IsDebuggingEnabled ?? _hostingSettings.DebugMode;
        /// <inheritdoc/>
        public bool IsHosted => (HttpContext.Current != null || HostingEnvironment.IsHosted);
        public string MapPath(string path)
        {
            return HostingEnvironment.MapPath(path);
        }

        public string ToAbsolute(string virtualPath, string root) => VirtualPathUtility.ToAbsolute(virtualPath, root);
        public void LazyRestartApplication()
        {
            HttpRuntime.UnloadAppDomain();
        }

        private IDictionary<IRegisteredObject, RegisteredObjectWrapper> RegisteredObjects { get;  } = new Dictionary<IRegisteredObject, RegisteredObjectWrapper>();

        public void RegisterObject(IRegisteredObject registeredObject)
        {
            var wrapped = new RegisteredObjectWrapper(registeredObject);
            RegisteredObjects.Add(registeredObject, wrapped);

            HostingEnvironment.RegisterObject(wrapped);
        }

        public void UnregisterObject(IRegisteredObject registeredObject)
        {
            if (RegisteredObjects.TryGetValue(registeredObject, out var wrapped))
            {
                HostingEnvironment.UnregisterObject(wrapped);<commit_msg>AB3986 - Changed dictionary to be concurrent to ensure thread safety.<commit_after>using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Web;
using System.Web.Hosting;
using Umbraco.Core;
using Umbraco.Core.Configuration;
using Umbraco.Core.Hosting;
using Umbraco.Core.IO;
using IRegisteredObject = Umbraco.Core.IRegisteredObject;

namespace Umbraco.Web.Hosting
{
    public class AspNetHostingEnvironment : IHostingEnvironment
    {
        private readonly ConcurrentDictionary<IRegisteredObject, RegisteredObjectWrapper> _registeredObjects =
            new ConcurrentDictionary<IRegisteredObject, RegisteredObjectWrapper>();
        private readonly IHostingSettings _hostingSettings;
        private string _localTempPath;

        public AspNetHostingEnvironment(IHostingSettings hostingSettings)
        {
            _hostingSettings = hostingSettings ?? throw new ArgumentNullException(nameof(hostingSettings));
            SiteName = HostingEnvironment.SiteName;
            ApplicationId = HostingEnvironment.ApplicationID;
            ApplicationPhysicalPath = HostingEnvironment.ApplicationPhysicalPath;
            ApplicationVirtualPath = HostingEnvironment.ApplicationVirtualPath;
            CurrentDomainId = AppDomain.CurrentDomain.Id;
        }

        public int CurrentDomainId { get; }

        public string SiteName { get; }
        public string ApplicationId { get; }
        public string ApplicationPhysicalPath { get; }

        public string ApplicationVirtualPath { get; }
        public bool IsDebugMode => HttpContext.Current?.IsDebuggingEnabled ?? _hostingSettings.DebugMode;
        /// <inheritdoc/>
        public bool IsHosted => (HttpContext.Current != null || HostingEnvironment.IsHosted);
        public string MapPath(string path)
        {
            return HostingEnvironment.MapPath(path);
        }

        public string ToAbsolute(string virtualPath, string root) => VirtualPathUtility.ToAbsolute(virtualPath, root);
        public void LazyRestartApplication()
        {
            HttpRuntime.UnloadAppDomain();
        }

        public void RegisterObject(IRegisteredObject registeredObject)
        {
            var wrapped = new RegisteredObjectWrapper(registeredObject);
            if (!_registeredObjects.TryAdd(registeredObject, wrapped))
            {
                throw new InvalidOperationException("Could not register object");
            }
            HostingEnvironment.RegisterObject(wrapped);
        }

        public void UnregisterObject(IRegisteredObject registeredObject)
        {
            if (_registeredObjects.TryGetValue(registeredObject, out var wrapped))
            {
                HostingEnvironment.UnregisterObject(wrapped);
{'fraction_non_alphanumeric': 0.06762832521543649, 'fraction_numerical': 0.0007493443237167478, 'mean_word_length': 3.1291569992266046, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '671055', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1248, 'n_words': 279}