diff --git a/src/Umbraco.Core/Security/IBackOfficeSecurityFactory.cs b/src/Umbraco.Core/Security/IBackOfficeSecurityFactory.cs
deleted file mode 100644
index ee553e85e6..0000000000
--- a/src/Umbraco.Core/Security/IBackOfficeSecurityFactory.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-namespace Umbraco.Cms.Core.Security
-{
- ///
- /// Creates and manages instances.
- ///
- public interface IBackOfficeSecurityFactory
- {
- ///
- /// Ensures that a current exists.
- ///
- void EnsureBackOfficeSecurity();
- }
-}
diff --git a/src/Umbraco.Core/Security/IBackofficeSecurityAccessor.cs b/src/Umbraco.Core/Security/IBackofficeSecurityAccessor.cs
index dbc64f40c7..2999ceacf4 100644
--- a/src/Umbraco.Core/Security/IBackofficeSecurityAccessor.cs
+++ b/src/Umbraco.Core/Security/IBackofficeSecurityAccessor.cs
@@ -1,7 +1,7 @@
-namespace Umbraco.Cms.Core.Security
+namespace Umbraco.Cms.Core.Security
{
public interface IBackOfficeSecurityAccessor
{
- IBackOfficeSecurity BackOfficeSecurity { get; set; }
+ IBackOfficeSecurity BackOfficeSecurity { get; }
}
}
diff --git a/src/Umbraco.Infrastructure/HostedServices/ScheduledPublishing.cs b/src/Umbraco.Infrastructure/HostedServices/ScheduledPublishing.cs
index 0fc1809250..ff93940c61 100644
--- a/src/Umbraco.Infrastructure/HostedServices/ScheduledPublishing.cs
+++ b/src/Umbraco.Infrastructure/HostedServices/ScheduledPublishing.cs
@@ -27,7 +27,6 @@ namespace Umbraco.Cms.Infrastructure.HostedServices
private readonly IMainDom _mainDom;
private readonly IRuntimeState _runtimeState;
private readonly IServerMessenger _serverMessenger;
- private readonly IBackOfficeSecurityFactory _backofficeSecurityFactory;
private readonly IServerRoleAccessor _serverRegistrar;
private readonly IUmbracoContextFactory _umbracoContextFactory;
@@ -49,8 +48,7 @@ namespace Umbraco.Cms.Infrastructure.HostedServices
IContentService contentService,
IUmbracoContextFactory umbracoContextFactory,
ILogger logger,
- IServerMessenger serverMessenger,
- IBackOfficeSecurityFactory backofficeSecurityFactory)
+ IServerMessenger serverMessenger)
: base(TimeSpan.FromMinutes(1), DefaultDelay)
{
_runtimeState = runtimeState;
@@ -60,7 +58,6 @@ namespace Umbraco.Cms.Infrastructure.HostedServices
_umbracoContextFactory = umbracoContextFactory;
_logger = logger;
_serverMessenger = serverMessenger;
- _backofficeSecurityFactory = backofficeSecurityFactory;
}
internal override Task PerformExecuteAsync(object state)
@@ -107,11 +104,6 @@ namespace Umbraco.Cms.Infrastructure.HostedServices
// but then what should be its "scope"? could we attach it to scopes?
// - and we should definitively *not* have to flush it here (should be auto)
- // TODO: This dependency chain is broken and needs to be fixed.
- // This is required to be called before EnsureUmbracoContext else the UmbracoContext's IBackOfficeSecurity instance is null
- // This is a very ugly Temporal Coupling which also means that developers can no longer just use IUmbracoContextFactory the
- // way it was intended.
- _backofficeSecurityFactory.EnsureBackOfficeSecurity();
using UmbracoContextReference contextReference = _umbracoContextFactory.EnsureUmbracoContext();
try
{
diff --git a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs
index 4b167cc2e1..a34e7d6fd1 100644
--- a/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs
+++ b/src/Umbraco.Tests.Integration/TestServerTest/UmbracoTestServerTestBase.cs
@@ -107,7 +107,6 @@ namespace Umbraco.Cms.Tests.Integration.TestServerTest
/// The string URL of the controller action.
protected string PrepareUrl(string url)
{
- IBackOfficeSecurityFactory backofficeSecurityFactory = GetRequiredService();
IUmbracoContextFactory umbracoContextFactory = GetRequiredService();
IHttpContextAccessor httpContextAccessor = GetRequiredService();
@@ -122,11 +121,6 @@ namespace Umbraco.Cms.Tests.Integration.TestServerTest
}
};
- // TODO: This dependency chain is broken and needs to be fixed.
- // This is required to be called before EnsureUmbracoContext else the UmbracoContext's IBackOfficeSecurity instance is null
- // This is a very ugly Temporal Coupling which also means that developers can no longer just use IUmbracoContextFactory the
- // way it was intended.
- backofficeSecurityFactory.EnsureBackOfficeSecurity();
umbracoContextFactory.EnsureUmbracoContext();
return url;
diff --git a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Filters/ContentModelValidatorTests.cs b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Filters/ContentModelValidatorTests.cs
index 91432f142e..99d1c7d1fd 100644
--- a/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Filters/ContentModelValidatorTests.cs
+++ b/src/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Filters/ContentModelValidatorTests.cs
@@ -138,8 +138,6 @@ namespace Umbraco.Cms.Tests.Integration.Umbraco.Web.BackOffice.Filters
public void Validating_ContentItemSave()
{
ILogger logger = Services.GetRequiredService>();
- IBackOfficeSecurityFactory backofficeSecurityFactory = Services.GetRequiredService();
- backofficeSecurityFactory.EnsureBackOfficeSecurity();
IPropertyValidationService propertyValidationService = Services.GetRequiredService();
UmbracoMapper umbracoMapper = Services.GetRequiredService();
diff --git a/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs b/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs
index 1eaa6dba16..20fa133e6a 100644
--- a/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs
+++ b/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs
@@ -265,7 +265,6 @@ namespace Umbraco.Extensions
// register the umbraco context factory
builder.Services.AddUnique();
- builder.Services.AddUnique();
builder.Services.AddUnique();
builder.AddNotificationHandler();
builder.Services.AddUnique();
@@ -289,6 +288,7 @@ namespace Umbraco.Extensions
builder.Services.AddScoped();
builder.Services.AddScoped();
+ builder.Services.AddScoped();
builder.AddHttpClients();
diff --git a/src/Umbraco.Web.Common/Middleware/UmbracoRequestMiddleware.cs b/src/Umbraco.Web.Common/Middleware/UmbracoRequestMiddleware.cs
index 467ec29451..295ac4e0e3 100644
--- a/src/Umbraco.Web.Common/Middleware/UmbracoRequestMiddleware.cs
+++ b/src/Umbraco.Web.Common/Middleware/UmbracoRequestMiddleware.cs
@@ -36,7 +36,6 @@ namespace Umbraco.Cms.Web.Common.Middleware
private readonly IUmbracoContextFactory _umbracoContextFactory;
private readonly IRequestCache _requestCache;
- private readonly IBackOfficeSecurityFactory _backofficeSecurityFactory;
private readonly PublishedSnapshotServiceEventHandler _publishedSnapshotServiceEventHandler;
private readonly IEventAggregator _eventAggregator;
private readonly IHostingEnvironment _hostingEnvironment;
@@ -52,7 +51,6 @@ namespace Umbraco.Cms.Web.Common.Middleware
ILogger logger,
IUmbracoContextFactory umbracoContextFactory,
IRequestCache requestCache,
- IBackOfficeSecurityFactory backofficeSecurityFactory,
PublishedSnapshotServiceEventHandler publishedSnapshotServiceEventHandler,
IEventAggregator eventAggregator,
IProfiler profiler,
@@ -61,7 +59,6 @@ namespace Umbraco.Cms.Web.Common.Middleware
_logger = logger;
_umbracoContextFactory = umbracoContextFactory;
_requestCache = requestCache;
- _backofficeSecurityFactory = backofficeSecurityFactory;
_publishedSnapshotServiceEventHandler = publishedSnapshotServiceEventHandler;
_eventAggregator = eventAggregator;
_hostingEnvironment = hostingEnvironment;
@@ -84,11 +81,6 @@ namespace Umbraco.Cms.Web.Common.Middleware
EnsureContentCacheInitialized();
- // TODO: This dependency chain is broken and needs to be fixed.
- // This is required to be called before EnsureUmbracoContext else the UmbracoContext's IBackOfficeSecurity instance is null
- // This is ugly Temporal Coupling which also means that developers can no longer just use IUmbracoContextFactory the
- // way it was intended.
- _backofficeSecurityFactory.EnsureBackOfficeSecurity();
UmbracoContextReference umbracoContextReference = _umbracoContextFactory.EnsureUmbracoContext();
Uri currentApplicationUrl = GetApplicationUrlFromCurrentRequest(context.Request);
diff --git a/src/Umbraco.Web.Common/Security/BackOfficeSecurityAccessor.cs b/src/Umbraco.Web.Common/Security/BackOfficeSecurityAccessor.cs
index ea2fc8c3e7..d773e20d25 100644
--- a/src/Umbraco.Web.Common/Security/BackOfficeSecurityAccessor.cs
+++ b/src/Umbraco.Web.Common/Security/BackOfficeSecurityAccessor.cs
@@ -1,4 +1,5 @@
using Microsoft.AspNetCore.Http;
+using Microsoft.Extensions.DependencyInjection;
using Umbraco.Cms.Core.Security;
namespace Umbraco.Cms.Web.Common.Security
@@ -13,12 +14,9 @@ namespace Umbraco.Cms.Web.Common.Security
public BackOfficeSecurityAccessor(IHttpContextAccessor httpContextAccessor) => _httpContextAccessor = httpContextAccessor;
///
- /// Gets or sets the object.
+ /// Gets the current object.
///
public IBackOfficeSecurity BackOfficeSecurity
- {
- get => _httpContextAccessor.HttpContext?.Features.Get();
- set => _httpContextAccessor.HttpContext?.Features.Set(value);
- }
+ => _httpContextAccessor.HttpContext?.RequestServices.GetService();
}
}
diff --git a/src/Umbraco.Web.Common/Security/BackofficeSecurity.cs b/src/Umbraco.Web.Common/Security/BackofficeSecurity.cs
index d7a0aeb043..24a5b01832 100644
--- a/src/Umbraco.Web.Common/Security/BackofficeSecurity.cs
+++ b/src/Umbraco.Web.Common/Security/BackofficeSecurity.cs
@@ -1,4 +1,4 @@
-using Microsoft.AspNetCore.Http;
+using Microsoft.AspNetCore.Http;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models.Membership;
using Umbraco.Cms.Core.Security;
diff --git a/src/Umbraco.Web.Common/Security/BackofficeSecurityFactory.cs b/src/Umbraco.Web.Common/Security/BackofficeSecurityFactory.cs
deleted file mode 100644
index 0b10fde322..0000000000
--- a/src/Umbraco.Web.Common/Security/BackofficeSecurityFactory.cs
+++ /dev/null
@@ -1,34 +0,0 @@
-using Microsoft.AspNetCore.Http;
-using Umbraco.Cms.Core.Security;
-using Umbraco.Cms.Core.Services;
-
-namespace Umbraco.Cms.Web.Common.Security
-{
- // TODO: This is only for the back office, does it need to be in common? YES currently UmbracoContext has an transitive dependency on this which needs to be fixed/reviewed.
-
- public class BackOfficeSecurityFactory: IBackOfficeSecurityFactory
- {
- private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor;
- private readonly IUserService _userService;
- private readonly IHttpContextAccessor _httpContextAccessor;
-
- public BackOfficeSecurityFactory(
- IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
- IUserService userService,
- IHttpContextAccessor httpContextAccessor)
- {
- _backOfficeSecurityAccessor = backOfficeSecurityAccessor;
- _userService = userService;
- _httpContextAccessor = httpContextAccessor;
- }
-
- public void EnsureBackOfficeSecurity()
- {
- if (_backOfficeSecurityAccessor.BackOfficeSecurity is null)
- {
- _backOfficeSecurityAccessor.BackOfficeSecurity = new BackOfficeSecurity(_userService, _httpContextAccessor);
- }
-
- }
- }
-}