using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Core.Security; namespace Umbraco.Cms.Web.Common.Security; public class BackOfficeSecurityAccessor : IBackOfficeSecurityAccessor { private readonly IHttpContextAccessor _httpContextAccessor; /// /// Initializes a new instance of the class. /// public BackOfficeSecurityAccessor(IHttpContextAccessor httpContextAccessor) => _httpContextAccessor = httpContextAccessor; /// /// Gets the current object. /// // RequestServices can be null when testing, even though compiler says it can't public IBackOfficeSecurity? BackOfficeSecurity => _httpContextAccessor.HttpContext?.RequestServices?.GetService(); }