From 33ed19da1bf99048eacdfb2830d75843253dc7f5 Mon Sep 17 00:00:00 2001 From: Stephan Date: Sun, 31 Jul 2016 19:44:48 +0200 Subject: [PATCH] Resvolution - ContentFinderResolver --- src/Umbraco.Web/Current.cs | 3 ++ src/Umbraco.Web/Routing/AliasUrlProvider.cs | 2 +- .../Routing/ContentFinderCollection.cs | 12 +++++ .../Routing/ContentFinderCollectionBuilder.cs | 14 ++++++ .../Routing/ContentFinderResolver.cs | 44 ------------------- src/Umbraco.Web/Umbraco.Web.csproj | 3 +- src/Umbraco.Web/UmbracoContext.cs | 2 +- src/Umbraco.Web/WebBootManager.cs | 22 +++++----- 8 files changed, 43 insertions(+), 59 deletions(-) create mode 100644 src/Umbraco.Web/Routing/ContentFinderCollection.cs create mode 100644 src/Umbraco.Web/Routing/ContentFinderCollectionBuilder.cs delete mode 100644 src/Umbraco.Web/Routing/ContentFinderResolver.cs diff --git a/src/Umbraco.Web/Current.cs b/src/Umbraco.Web/Current.cs index 4c3f1171c6..c0d8a1979a 100644 --- a/src/Umbraco.Web/Current.cs +++ b/src/Umbraco.Web/Current.cs @@ -129,6 +129,9 @@ namespace Umbraco.Web public static MigrationCollectionBuilder MigrationCollectionBuilder => Container.GetInstance(); + public static ContentFinderCollection ContentFinders + => Container.GetInstance(); + #endregion #region Core Getters diff --git a/src/Umbraco.Web/Routing/AliasUrlProvider.cs b/src/Umbraco.Web/Routing/AliasUrlProvider.cs index e9c737330e..c1661ae838 100644 --- a/src/Umbraco.Web/Routing/AliasUrlProvider.cs +++ b/src/Umbraco.Web/Routing/AliasUrlProvider.cs @@ -97,7 +97,7 @@ namespace Umbraco.Web.Routing //TODO: The ContentFinderResolver instance should be injected in ctor with DI instead of using singleton! // finder - if (ContentFinderResolver.Current.ContainsType()) + if (Current.ContentFinders.Any(x => x is ContentFinderByUrlAlias)) return true; diff --git a/src/Umbraco.Web/Routing/ContentFinderCollection.cs b/src/Umbraco.Web/Routing/ContentFinderCollection.cs new file mode 100644 index 0000000000..c8e45d4f2b --- /dev/null +++ b/src/Umbraco.Web/Routing/ContentFinderCollection.cs @@ -0,0 +1,12 @@ +using System.Collections.Generic; +using Umbraco.Core.DependencyInjection; + +namespace Umbraco.Web.Routing +{ + public class ContentFinderCollection : BuilderCollectionBase + { + public ContentFinderCollection(IEnumerable items) + : base(items) + { } + } +} diff --git a/src/Umbraco.Web/Routing/ContentFinderCollectionBuilder.cs b/src/Umbraco.Web/Routing/ContentFinderCollectionBuilder.cs new file mode 100644 index 0000000000..14e9f1ac29 --- /dev/null +++ b/src/Umbraco.Web/Routing/ContentFinderCollectionBuilder.cs @@ -0,0 +1,14 @@ +using LightInject; +using Umbraco.Core.DependencyInjection; + +namespace Umbraco.Web.Routing +{ + public class ContentFinderCollectionBuilder : OrderedCollectionBuilderBase + { + public ContentFinderCollectionBuilder(IServiceContainer container) + : base(container) + { } + + protected override ContentFinderCollectionBuilder This => this; + } +} diff --git a/src/Umbraco.Web/Routing/ContentFinderResolver.cs b/src/Umbraco.Web/Routing/ContentFinderResolver.cs deleted file mode 100644 index 22b953bdea..0000000000 --- a/src/Umbraco.Web/Routing/ContentFinderResolver.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Collections.Generic; -using LightInject; -using Umbraco.Core.Logging; -using Umbraco.Core.ObjectResolution; - -namespace Umbraco.Web.Routing -{ - /// - /// Resolves IPublishedContentFinder objects. - /// - public sealed class ContentFinderResolver : ContainerManyObjectsResolver - { - /// - /// Initializes a new instance of the class with an initial list of finder types. - /// - /// - /// - /// The list of finder types - /// The resolver is created by the WebBootManager and thus the constructor remains internal. - internal ContentFinderResolver(IServiceContainer container, ILogger logger, IEnumerable finders) - : base(container, logger, finders) - { } - - /// - /// Initializes a new instance of the class with an initial list of finder types. - /// - /// - /// The list of finder types - /// - /// The resolver is created by the WebBootManager and thus the constructor remains internal. - internal ContentFinderResolver(IServiceContainer container, ILogger logger, params Type[] finders) - : base(container, logger, finders) - { } - - /// - /// Gets the finders. - /// - public IEnumerable Finders - { - get { return Values; } - } - } -} diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj index 04797ecae6..10645b4f3e 100644 --- a/src/Umbraco.Web/Umbraco.Web.csproj +++ b/src/Umbraco.Web/Umbraco.Web.csproj @@ -262,6 +262,8 @@ + + @@ -1099,7 +1101,6 @@ - diff --git a/src/Umbraco.Web/UmbracoContext.cs b/src/Umbraco.Web/UmbracoContext.cs index 8f224edd8b..0ccaa37ffb 100644 --- a/src/Umbraco.Web/UmbracoContext.cs +++ b/src/Umbraco.Web/UmbracoContext.cs @@ -110,7 +110,7 @@ namespace Umbraco.Web umbracoContext, //TODO: Until the new cache is done we can't really expose these to override/mock - new Lazy>(() => ContentFinderResolver.Current.Finders), + new Lazy>(() => Web.Current.ContentFinders), new Lazy(() => ContentLastChanceFinderResolver.Current.Finder), // create the nice urls provider diff --git a/src/Umbraco.Web/WebBootManager.cs b/src/Umbraco.Web/WebBootManager.cs index 277fd3b0be..a7ffc1a7b4 100644 --- a/src/Umbraco.Web/WebBootManager.cs +++ b/src/Umbraco.Web/WebBootManager.cs @@ -517,18 +517,16 @@ namespace Umbraco.Web ContentLastChanceFinderResolver.Current = new ContentLastChanceFinderResolver(Container); Container.Register(); - ContentFinderResolver.Current = new ContentFinderResolver( - Container, ProfilingLogger.Logger, - // all built-in finders in the correct order, devs can then modify this list - // on application startup, via an application event handler. - typeof(ContentFinderByPageIdQuery), - typeof(ContentFinderByNiceUrl), - typeof(ContentFinderByIdPath), - typeof(ContentFinderByNiceUrlAndTemplate), - typeof(ContentFinderByProfile), - typeof(ContentFinderByUrlAlias), - typeof(ContentFinderByRedirectUrl) - ); + ContentFinderCollectionBuilder.Register(Container) + // all built-in finders in the correct order, + // devs can then modify this list on application startup + .Append() + .Append() + .Append() + .Append() + .Append() + .Append() + .Append(); SiteDomainHelperResolver.Current = new SiteDomainHelperResolver(Container); Container.Register();