v9: 10540 Resolving UmbracoHelper in middleware was null
This commit is contained in:
@@ -161,6 +161,7 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection
|
||||
builder.Services.AddScoped<ITagQuery, TagQuery>();
|
||||
|
||||
builder.Services.AddUnique<IUmbracoTreeSearcherFields, UmbracoTreeSearcherFields>();
|
||||
builder.Services.AddSingleton<IPublishedContentQueryAccessor, PublishedContentQueryAccessor>();
|
||||
builder.Services.AddScoped<IPublishedContentQuery>(factory =>
|
||||
{
|
||||
var umbCtx = factory.GetRequiredService<IUmbracoContextAccessor>();
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace Umbraco.Cms.Core
|
||||
{
|
||||
public interface IPublishedContentQueryAccessor
|
||||
{
|
||||
IPublishedContentQuery PublishedContentQuery { get;}
|
||||
}
|
||||
}
|
||||
17
src/Umbraco.Infrastructure/PublishedContentQueryAccessor.cs
Normal file
17
src/Umbraco.Infrastructure/PublishedContentQueryAccessor.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Umbraco.Cms.Core
|
||||
{
|
||||
public class PublishedContentQueryAccessor : IPublishedContentQueryAccessor
|
||||
{
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
|
||||
public PublishedContentQueryAccessor(IServiceProvider serviceProvider)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
public IPublishedContentQuery PublishedContentQuery => _serviceProvider.GetRequiredService<IPublishedContentQuery>();
|
||||
|
||||
}
|
||||
}
|
||||
@@ -315,6 +315,7 @@ namespace Umbraco.Extensions
|
||||
|
||||
builder.Services.AddSingleton<ContentModelBinder>();
|
||||
|
||||
builder.Services.AddSingleton<IUmbracoHelperAccessor, UmbracoHelperAccessor>();
|
||||
builder.Services.AddScoped<UmbracoHelper>();
|
||||
builder.Services.AddScoped<IBackOfficeSecurity, BackOfficeSecurity>();
|
||||
|
||||
|
||||
7
src/Umbraco.Web.Common/IUmbracoHelperAccessor.cs
Normal file
7
src/Umbraco.Web.Common/IUmbracoHelperAccessor.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Umbraco.Cms.Web.Common
|
||||
{
|
||||
public interface IUmbracoHelperAccessor
|
||||
{
|
||||
UmbracoHelper UmbracoHelper { get;}
|
||||
}
|
||||
}
|
||||
22
src/Umbraco.Web.Common/UmbracoHelperAccessor.cs
Normal file
22
src/Umbraco.Web.Common/UmbracoHelperAccessor.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Umbraco.Cms.Web.Common
|
||||
{
|
||||
public class UmbracoHelperAccessor : IUmbracoHelperAccessor
|
||||
{
|
||||
private readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
public UmbracoHelperAccessor(IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
}
|
||||
public UmbracoHelper UmbracoHelper => _httpContextAccessor.HttpContext.RequestServices.GetRequiredService<UmbracoHelper>();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user