diff --git a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs index 5b7e4a336c..6ec5128e4a 100644 --- a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs +++ b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs @@ -161,6 +161,7 @@ namespace Umbraco.Cms.Infrastructure.DependencyInjection builder.Services.AddScoped(); builder.Services.AddUnique(); + builder.Services.AddSingleton(); builder.Services.AddScoped(factory => { var umbCtx = factory.GetRequiredService(); diff --git a/src/Umbraco.Infrastructure/IPublishedContentQueryAccessor.cs b/src/Umbraco.Infrastructure/IPublishedContentQueryAccessor.cs new file mode 100644 index 0000000000..f449c40d43 --- /dev/null +++ b/src/Umbraco.Infrastructure/IPublishedContentQueryAccessor.cs @@ -0,0 +1,7 @@ +namespace Umbraco.Cms.Core +{ + public interface IPublishedContentQueryAccessor + { + IPublishedContentQuery PublishedContentQuery { get;} + } +} diff --git a/src/Umbraco.Infrastructure/PublishedContentQueryAccessor.cs b/src/Umbraco.Infrastructure/PublishedContentQueryAccessor.cs new file mode 100644 index 0000000000..4c19292afa --- /dev/null +++ b/src/Umbraco.Infrastructure/PublishedContentQueryAccessor.cs @@ -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(); + + } +} diff --git a/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs b/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs index 957d5976e1..abe2537cf7 100644 --- a/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs +++ b/src/Umbraco.Web.Common/DependencyInjection/UmbracoBuilderExtensions.cs @@ -315,6 +315,7 @@ namespace Umbraco.Extensions builder.Services.AddSingleton(); + builder.Services.AddSingleton(); builder.Services.AddScoped(); builder.Services.AddScoped(); diff --git a/src/Umbraco.Web.Common/IUmbracoHelperAccessor.cs b/src/Umbraco.Web.Common/IUmbracoHelperAccessor.cs new file mode 100644 index 0000000000..9671468631 --- /dev/null +++ b/src/Umbraco.Web.Common/IUmbracoHelperAccessor.cs @@ -0,0 +1,7 @@ +namespace Umbraco.Cms.Web.Common +{ + public interface IUmbracoHelperAccessor + { + UmbracoHelper UmbracoHelper { get;} + } +} diff --git a/src/Umbraco.Web.Common/UmbracoHelperAccessor.cs b/src/Umbraco.Web.Common/UmbracoHelperAccessor.cs new file mode 100644 index 0000000000..765aca792a --- /dev/null +++ b/src/Umbraco.Web.Common/UmbracoHelperAccessor.cs @@ -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(); + + } +}