Merge pull request #7890 from umbraco/netcore/feature/ab5819-initialize-composers

NetCore: Initialize more services for .net core
This commit is contained in:
Shannon Deminick
2020-04-15 10:17:20 +10:00
committed by GitHub
25 changed files with 350 additions and 278 deletions

View File

@@ -4,7 +4,7 @@ using System.Linq;
using Umbraco.Core.Composing;
namespace Umbraco.Web.Actions
{
internal class ActionCollectionBuilder : LazyCollectionBuilderBase<ActionCollectionBuilder, ActionCollection, IAction>
public class ActionCollectionBuilder : LazyCollectionBuilderBase<ActionCollectionBuilder, ActionCollection, IAction>
{
protected override ActionCollectionBuilder This => this;

View File

@@ -21,7 +21,7 @@ namespace Umbraco.Core
/// </summary>
/// <param name="composition">The composition.</param>
/// <returns></returns>
internal static ActionCollectionBuilder Actions(this Composition composition)
public static ActionCollectionBuilder Actions(this Composition composition)
=> composition.WithCollectionBuilder<ActionCollectionBuilder>();
/// <summary>
@@ -45,7 +45,7 @@ namespace Umbraco.Core
/// </summary>
/// <param name="composition">The composition.</param>
/// <returns></returns>
internal static EditorValidatorCollectionBuilder EditorValidators(this Composition composition)
public static EditorValidatorCollectionBuilder EditorValidators(this Composition composition)
=> composition.WithCollectionBuilder<EditorValidatorCollectionBuilder>();
/// <summary>
@@ -81,7 +81,7 @@ namespace Umbraco.Core
/// <param name="composition">The composition.</param>
public static SectionCollectionBuilder Sections(this Composition composition)
=> composition.WithCollectionBuilder<SectionCollectionBuilder>();
/// <summary>
/// Gets the components collection builder.
/// </summary>

View File

@@ -31,5 +31,20 @@ namespace Umbraco.Core
/// </summary>
public static void RegisterUnique<TService>(this Composition composition, TService instance)
=> composition.RegisterUnique(typeof(TService), instance);
/// <summary>
/// Registers a unique service with an implementation type.
/// </summary>
public static void RegisterMultipleUnique<TService1, TService2, TImplementing>(this Composition composition)
where TImplementing : class, TService1, TService2
where TService1 : class
where TService2 : class
{
composition.RegisterUnique<TImplementing>();
composition.RegisterUnique<TService1>(factory => factory.GetInstance<TImplementing>());
composition.RegisterUnique<TService2>(factory => factory.GetInstance<TImplementing>());
}
}
}
}

View File

@@ -7,7 +7,7 @@ using Umbraco.Core.Models.Membership;
namespace Umbraco.Web.ContentApps
{
internal class ContentEditorContentAppFactory : IContentAppFactory
public class ContentEditorContentAppFactory : IContentAppFactory
{
// see note on ContentApp
internal const int Weight = -100;

View File

@@ -10,7 +10,7 @@ using Umbraco.Web.Models.ContentEditing;
namespace Umbraco.Web.ContentApps
{
internal class ListViewContentAppFactory : IContentAppFactory
public class ListViewContentAppFactory : IContentAppFactory
{
// see note on ContentApp
private const int Weight = -666;

View File

@@ -3,7 +3,7 @@ using Umbraco.Core.Events;
namespace Umbraco.Web
{
internal class DefaultEventMessagesFactory : IEventMessagesFactory
public class DefaultEventMessagesFactory : IEventMessagesFactory
{
private readonly IEventMessagesAccessor _eventMessagesAccessor;

View File

@@ -3,7 +3,7 @@ using Umbraco.Core.Events;
namespace Umbraco.Web
{
internal class HybridEventMessagesAccessor : HybridAccessorBase<EventMessages>, IEventMessagesAccessor
public class HybridEventMessagesAccessor : HybridAccessorBase<EventMessages>, IEventMessagesAccessor
{
protected override string ItemKey => "Umbraco.Core.Events.HybridEventMessagesAccessor";

View File

@@ -7,7 +7,7 @@ using Umbraco.Web.Sections;
namespace Umbraco.Web.Services
{
internal class SectionService : ISectionService
public class SectionService : ISectionService
{
private readonly IUserService _userService;
private readonly SectionCollection _sectionCollection;

View File

@@ -9,7 +9,7 @@ namespace Umbraco.Web.Services
/// <summary>
/// Implements <see cref="ITreeService"/>.
/// </summary>
internal class TreeService : ITreeService
public class TreeService : ITreeService
{
private readonly TreeCollection _treeCollection;

View File

@@ -2,7 +2,7 @@ namespace Umbraco.Web
{
public interface ISessionManager
{
object GetSessionValue(string sessionName);
void SetSessionValue(string sessionName, object value);
string GetSessionValue(string sessionName);
void SetSessionValue(string sessionName, string value);
}
}

View File

@@ -11,6 +11,8 @@ using Umbraco.Core.Persistence.Mappers;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Strings;
using Umbraco.Core.Sync;
using Umbraco.Web.Media.EmbedProviders;
using Umbraco.Web.Search;
namespace Umbraco.Core
{
@@ -84,7 +86,20 @@ namespace Umbraco.Core
public static ManifestFilterCollectionBuilder ManifestFilters(this Composition composition)
=> composition.WithCollectionBuilder<ManifestFilterCollectionBuilder>();
/// <summary>
/// Gets the backoffice OEmbed Providers collection builder.
/// </summary>
/// <param name="composition">The composition.</param>
public static EmbedProvidersCollectionBuilder OEmbedProviders(this Composition composition)
=> composition.WithCollectionBuilder<EmbedProvidersCollectionBuilder>();
/// <summary>
/// Gets the back office searchable tree collection builder
/// </summary>
/// <param name="composition"></param>
/// <returns></returns>
public static SearchableTreeCollectionBuilder SearchableTrees(this Composition composition)
=> composition.WithCollectionBuilder<SearchableTreeCollectionBuilder>();
#endregion
@@ -98,7 +113,7 @@ namespace Umbraco.Core
public static void SetCultureDictionaryFactory<T>(this Composition composition)
where T : ICultureDictionaryFactory
{
composition.RegisterUnique<ICultureDictionaryFactory, T>();
composition.RegisterUnique<ICultureDictionaryFactory, T>();
}
/// <summary>

View File

@@ -1,4 +1,5 @@
using System;
using Examine;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Composing.CompositionExtensions;
@@ -7,9 +8,11 @@ using Umbraco.Core.Configuration.Grid;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Dashboards;
using Umbraco.Core.Dictionary;
using Umbraco.Core.Events;
using Umbraco.Core.Hosting;
using Umbraco.Core.Logging;
using Umbraco.Core.Manifest;
using Umbraco.Core.Media;
using Umbraco.Core.Migrations;
using Umbraco.Core.Migrations.Install;
using Umbraco.Core.Migrations.PostMigrations;
@@ -17,19 +20,35 @@ using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.Persistence;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.PropertyEditors.Validators;
using Umbraco.Core.PropertyEditors.ValueConverters;
using Umbraco.Core.Scoping;
using Umbraco.Core.Serialization;
using Umbraco.Core.Services;
using Umbraco.Core.Services.Implement;
using Umbraco.Core.Strings;
using Umbraco.Core.Sync;
using Umbraco.Examine;
using Umbraco.Infrastructure.Media;
using Umbraco.Web;
using Umbraco.Web.Actions;
using Umbraco.Web.Cache;
using Umbraco.Web.ContentApps;
using Umbraco.Web.Editors;
using Umbraco.Web.Features;
using Umbraco.Web.HealthCheck;
using Umbraco.Web.HealthCheck.NotificationMethods;
using Umbraco.Web.Install;
using Umbraco.Web.Macros;
using Umbraco.Web.Media.EmbedProviders;
using Umbraco.Web.Migrations.PostMigrations;
using Umbraco.Web.Models.PublishedContent;
using Umbraco.Web.PropertyEditors;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.Routing;
using Umbraco.Web.Search;
using Umbraco.Web.Sections;
using Umbraco.Web.Services;
using Umbraco.Web.Templates;
using Umbraco.Web.Trees;
using IntegerValidator = Umbraco.Core.PropertyEditors.Validators.IntegerValidator;
@@ -42,7 +61,7 @@ namespace Umbraco.Core.Runtime
public override void Compose(Composition composition)
{
base.Compose(composition);
// composers
composition
.ComposeRepositories()
@@ -177,6 +196,165 @@ namespace Umbraco.Core.Runtime
// Config manipulator
composition.RegisterUnique<IConfigManipulator, JsonConfigManipulator>();
// register the http context and umbraco context accessors
// we *should* use the HttpContextUmbracoContextAccessor, however there are cases when
// we have no http context, eg when booting Umbraco or in background threads, so instead
// let's use an hybrid accessor that can fall back to a ThreadStatic context.
composition.RegisterUnique<IUmbracoContextAccessor, HybridUmbracoContextAccessor>();
// register the umbraco context factory
// composition.RegisterUnique<IUmbracoContextFactory, UmbracoContextFactory>();
composition.RegisterUnique<IPublishedUrlProvider, UrlProvider>();
composition.RegisterUnique<HtmlLocalLinkParser>();
composition.RegisterUnique<HtmlImageSourceParser>();
composition.RegisterUnique<HtmlUrlParser>();
composition.RegisterUnique<RichTextEditorPastedImages>();
// both TinyMceValueConverter (in Core) and RteMacroRenderingValueConverter (in Web) will be
// discovered when CoreBootManager configures the converters. We HAVE to remove one of them
// here because there cannot be two converters for one property editor - and we want the full
// RteMacroRenderingValueConverter that converts macros, etc. So remove TinyMceValueConverter.
// (the limited one, defined in Core, is there for tests) - same for others
composition.PropertyValueConverters()
.Remove<TinyMceValueConverter>()
.Remove<TextStringValueConverter>()
.Remove<MarkdownEditorValueConverter>();
composition.UrlProviders()
.Append<AliasUrlProvider>()
.Append<DefaultUrlProvider>();
composition.MediaUrlProviders()
.Append<DefaultMediaUrlProvider>();
composition.RegisterUnique<ISiteDomainHelper, SiteDomainHelper>();
// register properties fallback
composition.RegisterUnique<IPublishedValueFallback, PublishedValueFallback>();
composition.RegisterUnique<IImageUrlGenerator, ImageSharpImageUrlGenerator>();
composition.RegisterUnique<UmbracoFeatures>();
composition.Actions()
.Add(() => composition.TypeLoader.GetTypes<IAction>());
composition.EditorValidators()
.Add(() => composition.TypeLoader.GetTypes<IEditorValidator>());
composition.TourFilters();
// replace with web implementation
composition.RegisterUnique<IPublishedSnapshotRebuilder, PublishedSnapshotRebuilder>();
// register OEmbed providers - no type scanning - all explicit opt-in of adding types
// note: IEmbedProvider is not IDiscoverable - think about it if going for type scanning
composition.OEmbedProviders()
.Append<YouTube>()
.Append<Instagram>()
.Append<Twitter>()
.Append<Vimeo>()
.Append<DailyMotion>()
.Append<Flickr>()
.Append<Slideshare>()
.Append<Kickstarter>()
.Append<GettyImages>()
.Append<Ted>()
.Append<Soundcloud>()
.Append<Issuu>()
.Append<Hulu>()
.Append<Giphy>();
// register back office sections in the order we want them rendered
composition.Sections()
.Append<ContentSection>()
.Append<MediaSection>()
.Append<SettingsSection>()
.Append<PackagesSection>()
.Append<UsersSection>()
.Append<MembersSection>()
.Append<FormsSection>()
.Append<TranslationSection>();
// register known content apps
composition.ContentApps()
.Append<ListViewContentAppFactory>()
.Append<ContentEditorContentAppFactory>()
.Append<ContentInfoContentAppFactory>();
// register published router
composition.RegisterUnique<IPublishedRouter, PublishedRouter>();
// register *all* checks, except those marked [HideFromTypeFinder] of course
composition.HealthChecks()
.Add(() => composition.TypeLoader.GetTypes<HealthCheck>());
composition.WithCollectionBuilder<HealthCheckNotificationMethodCollectionBuilder>()
.Add(() => composition.TypeLoader.GetTypes<IHealthCheckNotificationMethod>());
composition.RegisterUnique<IContentLastChanceFinder, ContentFinderByConfigured404>();
composition.ContentFinders()
// all built-in finders in the correct order,
// devs can then modify this list on application startup
.Append<ContentFinderByPageIdQuery>()
.Append<ContentFinderByUrl>()
.Append<ContentFinderByIdPath>()
//.Append<ContentFinderByUrlAndTemplate>() // disabled, this is an odd finder
.Append<ContentFinderByUrlAlias>()
.Append<ContentFinderByRedirectUrl>();
composition.Register<UmbracoTreeSearcher>(Lifetime.Request);
composition.SearchableTrees()
.Add(() => composition.TypeLoader.GetTypes<ISearchableTree>());
// replace some services
composition.RegisterUnique<IEventMessagesFactory, DefaultEventMessagesFactory>();
composition.RegisterUnique<IEventMessagesAccessor, HybridEventMessagesAccessor>();
composition.RegisterUnique<ITreeService, TreeService>();
composition.RegisterUnique<ISectionService, SectionService>();
composition.RegisterUnique<IExamineManager, ExamineManager>();
// register distributed cache
composition.RegisterUnique(f => new DistributedCache(f.GetInstance<IServerMessenger>(), f.GetInstance<CacheRefresherCollection>()));
composition.Register<ITagQuery, TagQuery>(Lifetime.Request);
composition.RegisterUnique<HtmlLocalLinkParser>();
composition.RegisterUnique<HtmlUrlParser>();
composition.RegisterUnique<HtmlImageSourceParser>();
composition.RegisterUnique<RichTextEditorPastedImages>();
composition.RegisterUnique<IUmbracoTreeSearcherFields, UmbracoTreeSearcherFields>();
composition.Register<IPublishedContentQuery>(factory =>
{
var umbCtx = factory.GetInstance<IUmbracoContextAccessor>();
return new PublishedContentQuery(umbCtx.UmbracoContext.PublishedSnapshot, factory.GetInstance<IVariationContextAccessor>(), factory.GetInstance<IExamineManager>());
}, Lifetime.Request);
composition.RegisterUnique<IPublishedUrlProvider, UrlProvider>();
// register the http context and umbraco context accessors
// we *should* use the HttpContextUmbracoContextAccessor, however there are cases when
// we have no http context, eg when booting Umbraco or in background threads, so instead
// let's use an hybrid accessor that can fall back to a ThreadStatic context.
composition.RegisterUnique<IUmbracoContextAccessor, HybridUmbracoContextAccessor>();
// register accessors for cultures
composition.RegisterUnique<IDefaultCultureAccessor, DefaultCultureAccessor>();
}
}
}

View File

@@ -3,6 +3,7 @@ using Moq;
using NUnit.Framework;
using Umbraco.Core.Configuration;
using Umbraco.Core.IO;
using Umbraco.Tests.Common;
using Umbraco.Web;
using Umbraco.Web.Models;
using Umbraco.Web.Mvc;
@@ -15,11 +16,12 @@ namespace Umbraco.Tests.Web.Mvc
[Test]
public void Redirects_To_Root_When_Content_Published()
{
var mockUmbracoContext = new Mock<IUmbracoContext>();
mockUmbracoContext.Setup(x => x.Content.HasContent()).Returns(true);
var mockIOHelper = new Mock<IIOHelper>();
var mockGlobalSettings = new Mock<IGlobalSettings>();
var controller = new RenderNoContentController(mockUmbracoContext.Object, mockIOHelper.Object, mockGlobalSettings.Object);
var controller = new RenderNoContentController(new TestUmbracoContextAccessor(mockUmbracoContext.Object), mockIOHelper.Object, mockGlobalSettings.Object);
var result = controller.Index() as RedirectResult;
@@ -40,7 +42,7 @@ namespace Umbraco.Tests.Web.Mvc
var mockGlobalSettings = new Mock<IGlobalSettings>();
mockGlobalSettings.SetupGet(x => x.UmbracoPath).Returns(UmbracoPathSetting);
mockGlobalSettings.SetupGet(x => x.NoNodesViewPath).Returns(ViewPath);
var controller = new RenderNoContentController(mockUmbracoContext.Object, mockIOHelper.Object, mockGlobalSettings.Object);
var controller = new RenderNoContentController(new TestUmbracoContextAccessor(mockUmbracoContext.Object), mockIOHelper.Object, mockGlobalSettings.Object);
var result = controller.Index() as ViewResult;
Assert.IsNotNull(result);

View File

@@ -0,0 +1,45 @@
using System;
using Microsoft.AspNetCore.Http;
namespace Umbraco.Web.Common.AspNetCore
{
public class AspNetCoreCookieManager : ICookieManager
{
private readonly IHttpContextAccessor _httpContextAccessor;
public AspNetCoreCookieManager(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
public void ExpireCookie(string cookieName)
{
var httpContext = _httpContextAccessor.HttpContext;
if (httpContext is null) return;
var cookieValue = httpContext.Request.Cookies[cookieName];
httpContext.Response.Cookies.Append(cookieName, cookieValue, new CookieOptions()
{
Expires = DateTime.Now.AddYears(-1)
});
}
public string GetCookieValue(string cookieName)
{
return _httpContextAccessor.HttpContext?.Request.Cookies[cookieName];
}
public void SetCookieValue(string cookieName, string value)
{
_httpContextAccessor.HttpContext?.Response.Cookies.Append(cookieName, value);
}
public bool HasCookie(string cookieName)
{
return !(GetCookieValue(cookieName) is null);
}
}
}

View File

@@ -1,30 +0,0 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Umbraco.Net;
namespace Umbraco.Web.Common.AspNetCore
{
internal class AspNetCoreSessionIdResolver : ISessionIdResolver
{
private readonly IHttpContextAccessor _httpContextAccessor;
public AspNetCoreSessionIdResolver(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
public string SessionId
{
get
{
var httpContext = _httpContextAccessor?.HttpContext;
// If session isn't enabled this will throw an exception so we check
var sessionFeature = httpContext?.Features.Get<ISessionFeature>();
return sessionFeature != null
? httpContext?.Session?.Id
: "0";
}
}
}
}

View File

@@ -0,0 +1,47 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;
using Umbraco.Net;
namespace Umbraco.Web.Common.AspNetCore
{
internal class AspNetCoreSessionManager : ISessionIdResolver, ISessionManager
{
private readonly IHttpContextAccessor _httpContextAccessor;
public AspNetCoreSessionManager(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
/// <summary>
/// If session isn't enabled this will throw an exception so we check
/// </summary>
private bool IsSessionsAvailable => !(_httpContextAccessor.HttpContext?.Features.Get<ISessionFeature>() is null);
public string SessionId
{
get
{
var httpContext = _httpContextAccessor?.HttpContext;
return IsSessionsAvailable
? httpContext?.Session?.Id
: "0";
}
}
public string GetSessionValue(string sessionName)
{
if(!IsSessionsAvailable) return null;
return _httpContextAccessor.HttpContext?.Session.GetString(sessionName);
}
public void SetSessionValue(string sessionName, string value)
{
if(!IsSessionsAvailable) return;
_httpContextAccessor.HttpContext?.Session.SetString(sessionName, value);
}
}
}

View File

@@ -171,7 +171,7 @@ namespace Umbraco.Web.Common.Extensions
hostingEnvironment = new AspNetCoreHostingEnvironment(hostingSettings, webHostEnvironment);
ioHelper = new IOHelper(hostingEnvironment, globalSettings);
logger = SerilogLogger.CreateWithDefaultConfiguration(hostingEnvironment,
new AspNetCoreSessionIdResolver(httpContextAccessor),
new AspNetCoreSessionManager(httpContextAccessor),
// TODO: We need to avoid this, surely there's a way? See ContainerTests.BuildServiceProvider_Before_Host_Is_Configured
() => services.BuildServiceProvider().GetService<IRequestCache>(), coreDebug, ioHelper,
new AspNetCoreMarchal());

View File

@@ -2,18 +2,11 @@ using Microsoft.AspNetCore.Http;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Hosting;
using Umbraco.Core.Media;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Net;
using Umbraco.Core.Runtime;
using Umbraco.Core.Security;
using Umbraco.Infrastructure.Media;
using Umbraco.Web.Common.AspNetCore;
using Umbraco.Web.Common.Lifetime;
using Umbraco.Web.Models.PublishedContent;
using Umbraco.Web.PropertyEditors;
using Umbraco.Web.Routing;
using Umbraco.Web.Templates;
namespace Umbraco.Web.Common.Runtime
{
@@ -39,41 +32,16 @@ namespace Umbraco.Web.Common.Runtime
composition.RegisterUnique<IApplicationShutdownRegistry, AspNetCoreApplicationShutdownRegistry>();
// The umbraco request lifetime
composition.RegisterUnique<UmbracoRequestLifetime>();
composition.RegisterUnique<IUmbracoRequestLifetimeManager>(factory => factory.GetInstance<UmbracoRequestLifetime>());
composition.RegisterUnique<IUmbracoRequestLifetime>(factory => factory.GetInstance<UmbracoRequestLifetime>());
composition.RegisterMultipleUnique<IUmbracoRequestLifetime, IUmbracoRequestLifetimeManager, UmbracoRequestLifetime>();
//Password hasher
composition.RegisterUnique<IPasswordHasher, AspNetCorePasswordHasher>();
// register the http context and umbraco context accessors
// we *should* use the HttpContextUmbracoContextAccessor, however there are cases when
// we have no http context, eg when booting Umbraco or in background threads, so instead
// let's use an hybrid accessor that can fall back to a ThreadStatic context.
composition.RegisterUnique<IUmbracoContextAccessor, HybridUmbracoContextAccessor>();
composition.RegisterUnique<ICookieManager, AspNetCoreCookieManager>();
// register the umbraco context factory
// composition.RegisterUnique<IUmbracoContextFactory, UmbracoContextFactory>();
composition.RegisterUnique<IPublishedUrlProvider, UrlProvider>();
composition.RegisterUnique<HtmlLocalLinkParser>();
composition.RegisterUnique<HtmlImageSourceParser>();
composition.RegisterUnique<HtmlUrlParser>();
composition.RegisterUnique<RichTextEditorPastedImages>();
composition.UrlProviders()
.Append<AliasUrlProvider>()
.Append<DefaultUrlProvider>();
composition.MediaUrlProviders()
.Append<DefaultMediaUrlProvider>();
composition.RegisterUnique<ISiteDomainHelper, SiteDomainHelper>();
// register properties fallback
composition.RegisterUnique<IPublishedValueFallback, PublishedValueFallback>();
composition.RegisterUnique<IImageUrlGenerator, ImageSharpImageUrlGenerator>();
composition.RegisterMultipleUnique<ISessionIdResolver, ISessionManager, AspNetCoreSessionManager>();
}
}
}

View File

@@ -10,13 +10,15 @@ namespace Umbraco.Web.AspNet
{
}
public object GetSessionValue(string sessionName)
public string GetSessionValue(string sessionName)
{
return HttpContext.Current.Session[sessionName];
return HttpContext.Current?.Session[sessionName]?.ToString();
}
public void SetSessionValue(string sessionName, object value)
public void SetSessionValue(string sessionName, string value)
{
var httpContext = HttpContext.Current;
if (httpContext is null) return;
HttpContext.Current.Session[sessionName] = value;
}

View File

@@ -29,7 +29,7 @@ namespace Umbraco.Web.Composing.CompositionExtensions
.Add<TemplateMapDefinition>()
.Add<UserMapDefinition>()
.Add<LanguageMapDefinition>()
.Add<IdentityMapDefinition>();;
.Add<IdentityMapDefinition>();
composition.Register<CommonMapper>();
composition.Register<CommonTreeNodeMapper>();

View File

@@ -40,12 +40,7 @@ namespace Umbraco.Web
=> composition.WithCollectionBuilder<FilteredControllerFactoryCollectionBuilder>();
/// <summary>
/// Gets the backoffice OEmbed Providers collection builder.
/// </summary>
/// <param name="composition">The composition.</param>
public static EmbedProvidersCollectionBuilder OEmbedProviders(this Composition composition)
=> composition.WithCollectionBuilder<EmbedProvidersCollectionBuilder>();
/// <summary>
/// Gets the back office tree collection builder
@@ -55,14 +50,6 @@ namespace Umbraco.Web
public static TreeCollectionBuilder Trees(this Composition composition)
=> composition.WithCollectionBuilder<TreeCollectionBuilder>();
/// <summary>
/// Gets the back office searchable tree collection builder
/// </summary>
/// <param name="composition"></param>
/// <returns></returns>
public static SearchableTreeCollectionBuilder SearchableTrees(this Composition composition)
=> composition.WithCollectionBuilder<SearchableTreeCollectionBuilder>();
#endregion

View File

@@ -400,7 +400,7 @@ namespace Umbraco.Web.Macros
attributeValue = _requestAccessor.GetRequestValue(name);
break;
case '%':
attributeValue = _sessionManager.GetSessionValue(name)?.ToString();
attributeValue = _sessionManager.GetSessionValue(name);
if (string.IsNullOrEmpty(attributeValue))
attributeValue = _cookieManager.GetCookieValue(name);
break;

View File

@@ -8,20 +8,20 @@ namespace Umbraco.Web.Mvc
{
public class RenderNoContentController : Controller
{
private readonly IUmbracoContext _umbracoContext;
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
private readonly IIOHelper _ioHelper;
private readonly IGlobalSettings _globalSettings;
public RenderNoContentController(IUmbracoContext umbracoContext, IIOHelper ioHelper, IGlobalSettings globalSettings)
public RenderNoContentController(IUmbracoContextAccessor umbracoContextAccessor, IIOHelper ioHelper, IGlobalSettings globalSettings)
{
_umbracoContext = umbracoContext ?? throw new ArgumentNullException(nameof(umbracoContext));
_umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
_ioHelper = ioHelper ?? throw new ArgumentNullException(nameof(ioHelper));
_globalSettings = globalSettings ?? throw new ArgumentNullException(nameof(globalSettings));
}
public ActionResult Index()
{
var store = _umbracoContext.Content;
var store = _umbracoContextAccessor.UmbracoContext.Content;
if (store.HasContent())
{
// If there is actually content, go to the root.

View File

@@ -3,50 +3,28 @@ using System.Web.Security;
using Examine;
using Microsoft.AspNet.SignalR;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Composing;
using Umbraco.Core.Configuration;
using Umbraco.Core.Dictionary;
using Umbraco.Core.Events;
using Umbraco.Core.Hosting;
using Umbraco.Core.Install;
using Umbraco.Core.Migrations.PostMigrations;
using Umbraco.Core.Models.PublishedContent;
using Umbraco.Core.PropertyEditors.ValueConverters;
using Umbraco.Core.Runtime;
using Umbraco.Core.Security;
using Umbraco.Core.Services;
using Umbraco.Core.Sync;
using Umbraco.Web.Actions;
using Umbraco.Web.Cache;
using Umbraco.Web.Composing.CompositionExtensions;
using Umbraco.Web.ContentApps;
using Umbraco.Web.Editors;
using Umbraco.Web.Features;
using Umbraco.Web.HealthCheck;
using Umbraco.Web.Hosting;
using Umbraco.Web.Install;
using Umbraco.Web.Macros;
using Umbraco.Web.Media.EmbedProviders;
using Umbraco.Web.Models.PublishedContent;
using Umbraco.Web.Mvc;
using Umbraco.Web.PublishedCache;
using Umbraco.Web.Routing;
using Umbraco.Web.Search;
using Umbraco.Web.Sections;
using Umbraco.Web.Security;
using Umbraco.Web.Security.Providers;
using Umbraco.Web.Services;
using Umbraco.Web.SignalR;
using Umbraco.Web.Templates;
using Umbraco.Web.Trees;
using Umbraco.Web.WebApi;
using Umbraco.Web.PropertyEditors;
using Umbraco.Examine;
using Umbraco.Net;
using Umbraco.Web.AspNet;
using Umbraco.Core.Media;
using Umbraco.Infrastructure.Media;
namespace Umbraco.Web.Runtime
{
@@ -63,9 +41,7 @@ namespace Umbraco.Web.Runtime
composition.Register<IIpResolver, AspNetIpResolver>();
composition.Register<IUserAgentProvider, AspNetUserAgentProvider>();
composition.Register<AspNetSessionManager>(Lifetime.Singleton);
composition.Register<ISessionIdResolver>(factory => factory.GetInstance<AspNetSessionManager>(), Lifetime.Singleton);
composition.Register<ISessionManager>(factory => factory.GetInstance<AspNetSessionManager>(), Lifetime.Singleton);
composition.Register<IRequestAccessor, AspNetRequestAccessor>(Lifetime.Singleton);
@@ -73,8 +49,7 @@ namespace Umbraco.Web.Runtime
composition.Register<IPasswordHasher, AspNetPasswordHasher>();
composition.Register<IFilePermissionHelper, FilePermissionHelper>(Lifetime.Singleton);
composition.RegisterUnique<IHttpContextAccessor, AspNetHttpContextAccessor>(); // required for hybrid accessors
composition.RegisterUnique<ICookieManager, AspNetCookieManager>();
composition.ComposeWebMappingProfiles();
@@ -92,43 +67,14 @@ namespace Umbraco.Web.Runtime
composition.RegisterUnique<IMemberUserKeyProvider, MemberUserKeyProvider>();
composition.RegisterUnique<IPublicAccessChecker, PublicAccessChecker>();
// register accessors for cultures
composition.RegisterUnique<IDefaultCultureAccessor, DefaultCultureAccessor>();
// register the http context and umbraco context accessors
// we *should* use the HttpContextUmbracoContextAccessor, however there are cases when
// we have no http context, eg when booting Umbraco or in background threads, so instead
// let's use an hybrid accessor that can fall back to a ThreadStatic context.
composition.RegisterUnique<IUmbracoContextAccessor, HybridUmbracoContextAccessor>();
// register the umbraco context factory
composition.RegisterUnique<IUmbracoContextFactory, UmbracoContextFactory>();
composition.RegisterUnique<IPublishedUrlProvider, UrlProvider>();
// we should stop injecting UmbracoContext and always inject IUmbracoContextAccessor, however at the moment
// there are tons of places (controllers...) which require UmbracoContext in their ctor - so let's register
// a way to inject the UmbracoContext - DO NOT register this as Lifetime.Request since LI will dispose the context
// in it's own way but we don't want that to happen, we manage its lifetime ourselves.
composition.Register(factory => factory.GetInstance<IUmbracoContextAccessor>().UmbracoContext);
composition.RegisterUnique<IUmbracoTreeSearcherFields, UmbracoTreeSearcherFields>();
composition.Register<IPublishedContentQuery>(factory =>
{
var umbCtx = factory.GetInstance<IUmbracoContextAccessor>();
return new PublishedContentQuery(umbCtx.UmbracoContext.PublishedSnapshot, factory.GetInstance<IVariationContextAccessor>(), factory.GetInstance<IExamineManager>());
}, Lifetime.Request);
composition.Register<ITagQuery, TagQuery>(Lifetime.Request);
composition.RegisterUnique<ITemplateRenderer, TemplateRenderer>();
composition.RegisterUnique<IMacroRenderer, MacroRenderer>();
composition.RegisterUnique<IUmbracoComponentRenderer, UmbracoComponentRenderer>();
composition.RegisterUnique<HtmlLocalLinkParser>();
composition.RegisterUnique<HtmlUrlParser>();
composition.RegisterUnique<HtmlImageSourceParser>();
composition.RegisterUnique<RichTextEditorPastedImages>();
// register the umbraco helper - this is Transient! very important!
// also, if not level.Run, we cannot really use the helper (during upgrade...)
// so inject a "void" helper (not exactly pretty but...)
@@ -142,19 +88,8 @@ namespace Umbraco.Web.Runtime
else
composition.Register(_ => new UmbracoHelper());
// register distributed cache
composition.RegisterUnique(f => new DistributedCache(f.GetInstance<IServerMessenger>(), f.GetInstance<CacheRefresherCollection>()));
composition.RegisterUnique<RoutableDocumentFilter>();
// replace some services
composition.RegisterUnique<IEventMessagesFactory, DefaultEventMessagesFactory>();
composition.RegisterUnique<IEventMessagesAccessor, HybridEventMessagesAccessor>();
composition.RegisterUnique<ITreeService, TreeService>();
composition.RegisterUnique<ISectionService, SectionService>();
composition.RegisterUnique<IExamineManager, ExamineManager>();
// configure the container for web
composition.ConfigureForWeb();
@@ -162,21 +97,6 @@ namespace Umbraco.Web.Runtime
.ComposeUmbracoControllers(GetType().Assembly)
.SetDefaultRenderMvcController<RenderMvcController>(); // default controller for template views
composition.SearchableTrees()
.Add(() => composition.TypeLoader.GetTypes<ISearchableTree>());
composition.Register<UmbracoTreeSearcher>(Lifetime.Request);
composition.EditorValidators()
.Add(() => composition.TypeLoader.GetTypes<IEditorValidator>());
composition.TourFilters();
composition.RegisterUnique<UmbracoFeatures>();
composition.Actions()
.Add(() => composition.TypeLoader.GetTypes<IAction>());
//we need to eagerly scan controller types since they will need to be routed
composition.WithCollectionBuilder<SurfaceControllerTypeCollectionBuilder>()
.Add(composition.TypeLoader.GetSurfaceControllers());
@@ -184,113 +104,37 @@ namespace Umbraco.Web.Runtime
composition.WithCollectionBuilder<UmbracoApiControllerTypeCollectionBuilder>()
.Add(umbracoApiControllerTypes);
// both TinyMceValueConverter (in Core) and RteMacroRenderingValueConverter (in Web) will be
// discovered when CoreBootManager configures the converters. We HAVE to remove one of them
// here because there cannot be two converters for one property editor - and we want the full
// RteMacroRenderingValueConverter that converts macros, etc. So remove TinyMceValueConverter.
// (the limited one, defined in Core, is there for tests) - same for others
composition.PropertyValueConverters()
.Remove<TinyMceValueConverter>()
.Remove<TextStringValueConverter>()
.Remove<MarkdownEditorValueConverter>();
// add all known factories, devs can then modify this list on application
// startup either by binding to events or in their own global.asax
composition.FilteredControllerFactory()
.Append<RenderControllerFactory>();
composition.UrlProviders()
.Append<AliasUrlProvider>()
.Append<DefaultUrlProvider>();
composition.MediaUrlProviders()
.Append<DefaultMediaUrlProvider>();
composition.RegisterUnique<IImageUrlGenerator, ImageSharpImageUrlGenerator>();
composition.RegisterUnique<IContentLastChanceFinder, ContentFinderByConfigured404>();
composition.ContentFinders()
// all built-in finders in the correct order,
// devs can then modify this list on application startup
.Append<ContentFinderByPageIdQuery>()
.Append<ContentFinderByUrl>()
.Append<ContentFinderByIdPath>()
//.Append<ContentFinderByUrlAndTemplate>() // disabled, this is an odd finder
.Append<ContentFinderByUrlAlias>()
.Append<ContentFinderByRedirectUrl>();
composition.RegisterUnique<ISiteDomainHelper, SiteDomainHelper>();
// register *all* checks, except those marked [HideFromTypeFinder] of course
composition.HealthChecks()
.Add(() => composition.TypeLoader.GetTypes<HealthCheck.HealthCheck>());
composition.WithCollectionBuilder<HealthCheckNotificationMethodCollectionBuilder>()
.Add(() => composition.TypeLoader.GetTypes<HealthCheck.NotificationMethods.IHealthCheckNotificationMethod>());
// auto-register views
composition.RegisterAuto(typeof(UmbracoViewPage<>));
// register published router
composition.RegisterUnique<IPublishedRouter, PublishedRouter>();
// register preview SignalR hub
composition.RegisterUnique(_ => GlobalHost.ConnectionManager.GetHubContext<PreviewHub>());
// register properties fallback
composition.RegisterUnique<IPublishedValueFallback, PublishedValueFallback>();
// register known content apps
composition.ContentApps()
.Append<ListViewContentAppFactory>()
.Append<ContentEditorContentAppFactory>()
.Append<ContentInfoContentAppFactory>();
// register back office sections in the order we want them rendered
composition.Sections()
.Append<ContentSection>()
.Append<MediaSection>()
.Append<SettingsSection>()
.Append<PackagesSection>()
.Append<UsersSection>()
.Append<MembersSection>()
.Append<FormsSection>()
.Append<TranslationSection>();
// register back office trees
// the collection builder only accepts types inheriting from TreeControllerBase
// and will filter out those that are not attributed with TreeAttribute
composition.Trees()
.AddTreeControllers(umbracoApiControllerTypes.Where(x => typeof(TreeControllerBase).IsAssignableFrom(x)));
// register OEmbed providers - no type scanning - all explicit opt-in of adding types
// note: IEmbedProvider is not IDiscoverable - think about it if going for type scanning
composition.OEmbedProviders()
.Append<YouTube>()
.Append<Instagram>()
.Append<Twitter>()
.Append<Vimeo>()
.Append<DailyMotion>()
.Append<Flickr>()
.Append<Slideshare>()
.Append<Kickstarter>()
.Append<GettyImages>()
.Append<Ted>()
.Append<Soundcloud>()
.Append<Issuu>()
.Append<Hulu>()
.Append<Giphy>();
// replace with web implementation
composition.RegisterUnique<IPublishedSnapshotRebuilder, Migrations.PostMigrations.PublishedSnapshotRebuilder>();
// Config manipulator
composition.RegisterUnique<IConfigManipulator, XmlConfigManipulator>();
//ApplicationShutdownRegistry
// STUFF that do not have to be moved to .NET CORE
//----------------------------------------
composition.RegisterUnique<ICookieManager, AspNetCookieManager>();
composition.RegisterUnique<IApplicationShutdownRegistry, AspNetApplicationShutdownRegistry>();
composition.RegisterUnique<IConfigManipulator, XmlConfigManipulator>();
composition.RegisterUnique<IHttpContextAccessor, AspNetHttpContextAccessor>(); // required for hybrid accessors
composition.Register<AspNetSessionManager>(Lifetime.Singleton);
composition.Register<ISessionIdResolver>(factory => factory.GetInstance<AspNetSessionManager>(), Lifetime.Singleton);
composition.Register<ISessionManager>(factory => factory.GetInstance<AspNetSessionManager>(), Lifetime.Singleton);
}
}
}

View File

@@ -323,7 +323,6 @@
<Compile Include="Mvc\ValidateMvcAngularAntiForgeryTokenAttribute.cs" />
<Compile Include="OwinMiddlewareConfiguredEventArgs.cs" />
<Compile Include="Editors\RedirectUrlManagementController.cs" />
<Compile Include="DefaultEventMessagesFactory.cs" />
<Compile Include="Security\ExternalSignInAutoLinkOptions.cs" />
<Compile Include="Security\FixWindowsAuthMiddlware.cs" />
<Compile Include="Security\ForceRenewalCookieAuthenticationHandler.cs" />