From 132c3c0c8e420414a07178a893fba9a55d80247f Mon Sep 17 00:00:00 2001 From: Stephan Date: Fri, 1 Feb 2019 17:16:50 +0100 Subject: [PATCH] Cleanup PR, document and rename things --- .../Composing/Composers/ServicesComposer.cs | 2 +- src/Umbraco.Core/ContentExtensions.cs | 16 +-- src/Umbraco.Core/Models/Content.cs | 15 +-- src/Umbraco.Core/Models/ISimpleContentType.cs | 112 ++++++++---------- src/Umbraco.Core/Models/SimpleContentType.cs | 84 +++++++++++++ src/Umbraco.Core/ServiceContextExtensions.cs | 8 +- .../IContentTypeBaseServiceProvider.cs | 22 ++++ .../Services/IContentTypeService.cs | 2 +- .../Services/IContentTypeServiceBase.cs | 21 +++- .../IContentTypeServiceBaseFactory.cs | 10 -- .../Services/IMediaTypeService.cs | 2 +- .../Services/IMemberTypeService.cs | 2 +- ...y.cs => ContentTypeBaseServiceProvider.cs} | 7 +- .../ContentTypeServiceBaseOfTItemTService.cs | 2 +- ...peServiceBaseOfTRepositoryTItemTService.cs | 6 +- src/Umbraco.Core/Services/ServiceContext.cs | 13 +- src/Umbraco.Core/Umbraco.Core.csproj | 5 +- .../PublishedContent/NuCacheTests.cs | 4 +- .../Scoping/ScopedNuCacheTests.cs | 2 +- .../ContentTypeServiceVariantsTests.cs | 2 +- src/Umbraco.Tests/TestHelpers/TestObjects.cs | 2 +- src/Umbraco.Web/Editors/ContentController.cs | 2 +- .../Editors/ContentTypeController.cs | 2 +- src/Umbraco.Web/Editors/MediaController.cs | 8 +- .../PublishedContentHashtableConverter.cs | 2 +- .../Models/Mapping/ContentMapperProfile.cs | 4 +- .../Mapping/ContentTypeBasicResolver.cs | 8 +- .../Models/Mapping/MediaMapperProfile.cs | 4 +- .../NuCache/PublishedSnapshotService.cs | 8 +- 29 files changed, 237 insertions(+), 140 deletions(-) create mode 100644 src/Umbraco.Core/Models/SimpleContentType.cs create mode 100644 src/Umbraco.Core/Services/IContentTypeBaseServiceProvider.cs delete mode 100644 src/Umbraco.Core/Services/IContentTypeServiceBaseFactory.cs rename src/Umbraco.Core/Services/Implement/{ContentTypeServiceBaseFactory.cs => ContentTypeBaseServiceProvider.cs} (75%) diff --git a/src/Umbraco.Core/Composing/Composers/ServicesComposer.cs b/src/Umbraco.Core/Composing/Composers/ServicesComposer.cs index 1fe5dd7561..1e10585b8e 100644 --- a/src/Umbraco.Core/Composing/Composers/ServicesComposer.cs +++ b/src/Umbraco.Core/Composing/Composers/ServicesComposer.cs @@ -37,7 +37,7 @@ namespace Umbraco.Core.Composing.Composers composition.RegisterUnique(); composition.RegisterUnique(); composition.RegisterUnique(); - composition.RegisterUnique(); + composition.RegisterUnique(); composition.RegisterUnique(); composition.RegisterUnique(); composition.RegisterUnique(); diff --git a/src/Umbraco.Core/ContentExtensions.cs b/src/Umbraco.Core/ContentExtensions.cs index d4ec876565..5db080f3f3 100644 --- a/src/Umbraco.Core/ContentExtensions.cs +++ b/src/Umbraco.Core/ContentExtensions.cs @@ -166,7 +166,7 @@ namespace Umbraco.Core /// This really is for FileUpload fields only, and should be obsoleted. For anything else, /// you need to store the file by yourself using Store and then figure out /// how to deal with auto-fill properties (if any) and thumbnails (if any) by yourself. - public static void SetValue(this IContentBase content, IContentTypeServiceBaseFactory contentTypeServiceBaseFactory, string propertyTypeAlias, string filename, Stream filestream, string culture = null, string segment = null) + public static void SetValue(this IContentBase content, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, string propertyTypeAlias, string filename, Stream filestream, string culture = null, string segment = null) { if (filename == null || filestream == null) return; @@ -175,12 +175,12 @@ namespace Umbraco.Core if (string.IsNullOrWhiteSpace(filename)) return; filename = filename.ToLower(); - SetUploadFile(content,contentTypeServiceBaseFactory, propertyTypeAlias, filename, filestream, culture, segment); + SetUploadFile(content,contentTypeBaseServiceProvider, propertyTypeAlias, filename, filestream, culture, segment); } - private static void SetUploadFile(this IContentBase content, IContentTypeServiceBaseFactory contentTypeServiceBaseFactory, string propertyTypeAlias, string filename, Stream filestream, string culture = null, string segment = null) + private static void SetUploadFile(this IContentBase content, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, string propertyTypeAlias, string filename, Stream filestream, string culture = null, string segment = null) { - var property = GetProperty(content, contentTypeServiceBaseFactory, propertyTypeAlias); + var property = GetProperty(content, contentTypeBaseServiceProvider, propertyTypeAlias); // Fixes https://github.com/umbraco/Umbraco-CMS/issues/3937 - Assigning a new file to an // existing IMedia with extension SetValue causes exception 'Illegal characters in path' @@ -201,12 +201,12 @@ namespace Umbraco.Core } // gets or creates a property for a content item. - private static Property GetProperty(IContentBase content, IContentTypeServiceBaseFactory contentTypeServiceBaseFactory, string propertyTypeAlias) + private static Property GetProperty(IContentBase content, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, string propertyTypeAlias) { var property = content.Properties.FirstOrDefault(x => x.Alias.InvariantEquals(propertyTypeAlias)); if (property != null) return property; - var contentTypeService = contentTypeServiceBaseFactory.Create(content); + var contentTypeService = contentTypeBaseServiceProvider.For(content); var contentType = contentTypeService.Get(content.ContentTypeId); var propertyType = contentType.CompositionPropertyTypes .FirstOrDefault(x => x.Alias.InvariantEquals(propertyTypeAlias)); @@ -234,9 +234,9 @@ namespace Umbraco.Core /// the "folder number" that was assigned to the previous file referenced by the property, /// if any. /// - public static string StoreFile(this IContentBase content, IContentTypeServiceBaseFactory contentTypeServiceBaseFactory, string propertyTypeAlias, string filename, Stream filestream, string filepath) + public static string StoreFile(this IContentBase content, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, string propertyTypeAlias, string filename, Stream filestream, string filepath) { - var contentTypeService = contentTypeServiceBaseFactory.Create(content); + var contentTypeService = contentTypeBaseServiceProvider.For(content); var contentType = contentTypeService.Get(content.ContentTypeId); var propertyType = contentType .CompositionPropertyTypes.FirstOrDefault(x => x.Alias.InvariantEquals(propertyTypeAlias)); diff --git a/src/Umbraco.Core/Models/Content.cs b/src/Umbraco.Core/Models/Content.cs index d2f5e3d308..16b28e088a 100644 --- a/src/Umbraco.Core/Models/Content.cs +++ b/src/Umbraco.Core/Models/Content.cs @@ -15,8 +15,6 @@ namespace Umbraco.Core.Models [DataContract(IsReference = true)] public class Content : ContentBase, IContent { - private ISimpleContentType _contentType; - private ITemplate _template; private int? _templateId; private ContentScheduleCollection _schedule; private bool _published; @@ -50,7 +48,7 @@ namespace Umbraco.Core.Models : base(name, parent, contentType, properties, culture) { if (contentType == null) throw new ArgumentNullException(nameof(contentType)); - _contentType = new SimpleContentType(contentType); + ContentType = new SimpleContentType(contentType); _publishedState = PublishedState.Unpublished; PublishedVersionId = 0; } @@ -78,7 +76,7 @@ namespace Umbraco.Core.Models : base(name, parentId, contentType, properties, culture) { if (contentType == null) throw new ArgumentNullException(nameof(contentType)); - _contentType = new SimpleContentType(contentType); + ContentType = new SimpleContentType(contentType); _publishedState = PublishedState.Unpublished; PublishedVersionId = 0; } @@ -140,7 +138,6 @@ namespace Umbraco.Core.Models set => SetPropertyValueAndDetectChanges(value, ref _templateId, Ps.Value.TemplateSelector); } - /// /// Gets or sets a value indicating whether this content item is published or not. /// @@ -184,7 +181,7 @@ namespace Umbraco.Core.Models /// Gets the ContentType used by this content object /// [IgnoreDataMember] - public ISimpleContentType ContentType => _contentType; + public ISimpleContentType ContentType { get; private set; } /// [IgnoreDataMember] @@ -426,7 +423,7 @@ namespace Umbraco.Core.Models public void ChangeContentType(IContentType contentType) { ContentTypeId = contentType.Id; - _contentType = new SimpleContentType(contentType); + ContentType = new SimpleContentType(contentType); ContentTypeBase = contentType; Properties.EnsurePropertyTypes(PropertyTypes); @@ -445,7 +442,7 @@ namespace Umbraco.Core.Models if(clearProperties) { ContentTypeId = contentType.Id; - _contentType = new SimpleContentType(contentType); + ContentType = new SimpleContentType(contentType); ContentTypeBase = contentType; Properties.EnsureCleanPropertyTypes(PropertyTypes); @@ -500,7 +497,7 @@ namespace Umbraco.Core.Models var clonedContent = (Content)clone; //need to manually clone this since it's not settable - clonedContent._contentType = ContentType; + clonedContent.ContentType = ContentType; //if culture infos exist then deal with event bindings if (clonedContent._publishInfos != null) diff --git a/src/Umbraco.Core/Models/ISimpleContentType.cs b/src/Umbraco.Core/Models/ISimpleContentType.cs index 679a69520c..8c9413f934 100644 --- a/src/Umbraco.Core/Models/ISimpleContentType.cs +++ b/src/Umbraco.Core/Models/ISimpleContentType.cs @@ -1,79 +1,67 @@ -using System.Collections.Generic; - -namespace Umbraco.Core.Models +namespace Umbraco.Core.Models { /// - /// Defines a ContentType, which Content is based on + /// Represents a simplified view of a content type. /// public interface ISimpleContentType { + /// + /// Gets the alias of the content type. + /// string Alias { get; } + + /// + /// Gets the identifier of the content type. + /// int Id { get; } + + /// + /// Gets the default template of the content type. + /// ITemplate DefaultTemplate { get; } + + /// + /// Gets the content variation of the content type. + /// ContentVariation Variations { get; } + + /// + /// Gets the icon of the content type. + /// string Icon { get; } + + /// + /// Gets a value indicating whether the content type is a container. + /// bool IsContainer { get; } + + /// + /// Gets the name of the content type. + /// string Name { get; } + + /// + /// Gets a value indicating whether content of that type can be created at the root of the tree. + /// bool AllowedAsRoot { get; } + + /// + /// Gets a value indicating whether the content type is an element content type. + /// bool IsElement { get; } - bool SupportsPropertyVariation(string culture, string s, bool b); - } - public class SimpleContentType : ISimpleContentType - { - public SimpleContentType(IContentType contentType) - { - Id = contentType.Id; - Alias = contentType.Alias; - DefaultTemplate = contentType.DefaultTemplate; - Variations = contentType.Variations; - Icon = contentType.Icon; - IsContainer = contentType.IsContainer; - Icon = contentType.Icon; - Name = contentType.Name; - AllowedAsRoot = contentType.AllowedAsRoot; - IsElement = contentType.IsElement; - } - - public string Alias { get; } - public int Id { get; } - public ITemplate DefaultTemplate { get; } - public ContentVariation Variations { get; } - public string Icon { get; } - public bool IsContainer { get; } - public string Name { get; } - public bool AllowedAsRoot { get; } - public bool IsElement { get; } - - /// - public bool SupportsPropertyVariation(string culture, string segment, bool wildcards = false) - { - // non-exact validation: can accept a 'null' culture if the property type varies - // by culture, and likewise for segment - // wildcard validation: can accept a '*' culture or segment - return Variations.ValidateVariation(culture, segment, false, wildcards, false); - } - - - protected bool Equals(SimpleContentType other) - { - return string.Equals(Alias, other.Alias) && Id == other.Id; - } - - public override bool Equals(object obj) - { - if (ReferenceEquals(null, obj)) return false; - if (ReferenceEquals(this, obj)) return true; - if (obj.GetType() != this.GetType()) return false; - return Equals((SimpleContentType) obj); - } - - public override int GetHashCode() - { - unchecked - { - return ((Alias != null ? Alias.GetHashCode() : 0) * 397) ^ Id; - } - } + /// + /// Validates that a combination of culture and segment is valid for the content type properties. + /// + /// The culture. + /// The segment. + /// A value indicating whether wildcard are supported. + /// True if the combination is valid; otherwise false. + /// + /// The combination must be valid for properties of the content type. For instance, if the content type varies by culture, + /// then an invariant culture is valid, because some properties may be invariant. On the other hand, if the content type is invariant, + /// then a variant culture is invalid, because no property could possibly vary by culture. + /// + bool SupportsPropertyVariation(string culture, string segment, bool wildcards = false); } } diff --git a/src/Umbraco.Core/Models/SimpleContentType.cs b/src/Umbraco.Core/Models/SimpleContentType.cs new file mode 100644 index 0000000000..be1f87fcda --- /dev/null +++ b/src/Umbraco.Core/Models/SimpleContentType.cs @@ -0,0 +1,84 @@ +namespace Umbraco.Core.Models +{ + /// + /// Implements . + /// + public class SimpleContentType : ISimpleContentType + { + /// + /// Initializes a new instance of the class. + /// + public SimpleContentType(IContentType contentType) + { + Id = contentType.Id; + Alias = contentType.Alias; + DefaultTemplate = contentType.DefaultTemplate; + Variations = contentType.Variations; + Icon = contentType.Icon; + IsContainer = contentType.IsContainer; + Icon = contentType.Icon; + Name = contentType.Name; + AllowedAsRoot = contentType.AllowedAsRoot; + IsElement = contentType.IsElement; + } + + /// + public string Alias { get; } + + /// + public int Id { get; } + + /// + public ITemplate DefaultTemplate { get; } + + /// + public ContentVariation Variations { get; } + + /// + public string Icon { get; } + + /// + public bool IsContainer { get; } + + /// + public string Name { get; } + + /// + public bool AllowedAsRoot { get; } + + /// + public bool IsElement { get; } + + /// + public bool SupportsPropertyVariation(string culture, string segment, bool wildcards = false) + { + // non-exact validation: can accept a 'null' culture if the property type varies + // by culture, and likewise for segment + // wildcard validation: can accept a '*' culture or segment + return Variations.ValidateVariation(culture, segment, false, wildcards, false); + } + + protected bool Equals(SimpleContentType other) + { + return string.Equals(Alias, other.Alias) && Id == other.Id; + } + + /// + public override bool Equals(object obj) + { + if (ReferenceEquals(null, obj)) return false; + if (ReferenceEquals(this, obj)) return true; + if (obj.GetType() != GetType()) return false; + return Equals((SimpleContentType) obj); + } + + /// + public override int GetHashCode() + { + unchecked + { + return ((Alias != null ? Alias.GetHashCode() : 0) * 397) ^ Id; + } + } + } +} diff --git a/src/Umbraco.Core/ServiceContextExtensions.cs b/src/Umbraco.Core/ServiceContextExtensions.cs index b1ca021173..3af918815f 100644 --- a/src/Umbraco.Core/ServiceContextExtensions.cs +++ b/src/Umbraco.Core/ServiceContextExtensions.cs @@ -6,15 +6,15 @@ namespace Umbraco.Core { public static class ServiceContextExtensions { - public static IContentTypeServiceBase GetContentTypeService(this ServiceContext services) + public static IContentTypeBaseService GetContentTypeService(this ServiceContext services) where T : IContentTypeComposition { if (typeof(T).Implements()) - return services.ContentTypeService as IContentTypeServiceBase; + return services.ContentTypeService as IContentTypeBaseService; if (typeof(T).Implements()) - return services.MediaTypeService as IContentTypeServiceBase; + return services.MediaTypeService as IContentTypeBaseService; if (typeof(T).Implements()) - return services.MemberTypeService as IContentTypeServiceBase; + return services.MemberTypeService as IContentTypeBaseService; throw new ArgumentException("Type " + typeof(T).FullName + " does not have a service."); } } diff --git a/src/Umbraco.Core/Services/IContentTypeBaseServiceProvider.cs b/src/Umbraco.Core/Services/IContentTypeBaseServiceProvider.cs new file mode 100644 index 0000000000..70327e7baf --- /dev/null +++ b/src/Umbraco.Core/Services/IContentTypeBaseServiceProvider.cs @@ -0,0 +1,22 @@ +using Umbraco.Core.Models; + +namespace Umbraco.Core.Services +{ + /// + /// Provides the corresponding to an object. + /// + public interface IContentTypeBaseServiceProvider + { + /// + /// Gets the content type service base managing types for the specified content base. + /// + /// + /// If is an , this returns the + /// , and if it's an , this returns + /// the , etc. + /// Services are returned as and can be used + /// to retrieve the content / media / whatever type as . + /// + IContentTypeBaseService For(IContentBase contentBase); + } +} diff --git a/src/Umbraco.Core/Services/IContentTypeService.cs b/src/Umbraco.Core/Services/IContentTypeService.cs index bddd276e58..02e4bc6b18 100644 --- a/src/Umbraco.Core/Services/IContentTypeService.cs +++ b/src/Umbraco.Core/Services/IContentTypeService.cs @@ -7,7 +7,7 @@ namespace Umbraco.Core.Services /// /// Manages objects. /// - public interface IContentTypeService : IContentTypeServiceBase + public interface IContentTypeService : IContentTypeBaseService { /// /// Gets all property type aliases. diff --git a/src/Umbraco.Core/Services/IContentTypeServiceBase.cs b/src/Umbraco.Core/Services/IContentTypeServiceBase.cs index cd6f2f4911..8fa77e4836 100644 --- a/src/Umbraco.Core/Services/IContentTypeServiceBase.cs +++ b/src/Umbraco.Core/Services/IContentTypeServiceBase.cs @@ -4,8 +4,14 @@ using Umbraco.Core.Models; namespace Umbraco.Core.Services { - public interface IContentTypeServiceBase + /// + /// Provides a common base interface for . + /// + public interface IContentTypeBaseService { + /// + /// Gets a content type. + /// IContentTypeComposition Get(int id); } @@ -13,11 +19,22 @@ namespace Umbraco.Core.Services /// Provides a common base interface for , and . /// /// The type of the item. - public interface IContentTypeServiceBase : IContentTypeServiceBase, IService + public interface IContentTypeBaseService : IContentTypeBaseService, IService where TItem : IContentTypeComposition { + /// + /// Gets a content type. + /// TItem Get(int id); + + /// + /// Gets a content type. + /// TItem Get(Guid key); + + /// + /// Gets a content type. + /// TItem Get(string alias); int Count(); diff --git a/src/Umbraco.Core/Services/IContentTypeServiceBaseFactory.cs b/src/Umbraco.Core/Services/IContentTypeServiceBaseFactory.cs deleted file mode 100644 index c816863128..0000000000 --- a/src/Umbraco.Core/Services/IContentTypeServiceBaseFactory.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Umbraco.Core.Models; - -namespace Umbraco.Core.Services -{ - public interface IContentTypeServiceBaseFactory - { - IContentTypeServiceBase Create(IContentBase contentBase); - - } -} diff --git a/src/Umbraco.Core/Services/IMediaTypeService.cs b/src/Umbraco.Core/Services/IMediaTypeService.cs index b125f4ca13..992937675f 100644 --- a/src/Umbraco.Core/Services/IMediaTypeService.cs +++ b/src/Umbraco.Core/Services/IMediaTypeService.cs @@ -5,6 +5,6 @@ namespace Umbraco.Core.Services /// /// Manages objects. /// - public interface IMediaTypeService : IContentTypeServiceBase + public interface IMediaTypeService : IContentTypeBaseService { } } diff --git a/src/Umbraco.Core/Services/IMemberTypeService.cs b/src/Umbraco.Core/Services/IMemberTypeService.cs index e6dfef6998..41004d267d 100644 --- a/src/Umbraco.Core/Services/IMemberTypeService.cs +++ b/src/Umbraco.Core/Services/IMemberTypeService.cs @@ -5,7 +5,7 @@ namespace Umbraco.Core.Services /// /// Manages objects. /// - public interface IMemberTypeService : IContentTypeServiceBase + public interface IMemberTypeService : IContentTypeBaseService { string GetDefault(); } diff --git a/src/Umbraco.Core/Services/Implement/ContentTypeServiceBaseFactory.cs b/src/Umbraco.Core/Services/Implement/ContentTypeBaseServiceProvider.cs similarity index 75% rename from src/Umbraco.Core/Services/Implement/ContentTypeServiceBaseFactory.cs rename to src/Umbraco.Core/Services/Implement/ContentTypeBaseServiceProvider.cs index 64395d4e2d..d867224b90 100644 --- a/src/Umbraco.Core/Services/Implement/ContentTypeServiceBaseFactory.cs +++ b/src/Umbraco.Core/Services/Implement/ContentTypeBaseServiceProvider.cs @@ -3,20 +3,20 @@ using Umbraco.Core.Models; namespace Umbraco.Core.Services.Implement { - public class ContentTypeServiceBaseFactory : IContentTypeServiceBaseFactory + public class ContentTypeBaseServiceProvider : IContentTypeBaseServiceProvider { private readonly IContentTypeService _contentTypeService; private readonly IMediaTypeService _mediaTypeService; private readonly IMemberTypeService _memberTypeService; - public ContentTypeServiceBaseFactory(IContentTypeService contentTypeService, IMediaTypeService mediaTypeService, IMemberTypeService memberTypeService) + public ContentTypeBaseServiceProvider(IContentTypeService contentTypeService, IMediaTypeService mediaTypeService, IMemberTypeService memberTypeService) { _contentTypeService = contentTypeService; _mediaTypeService = mediaTypeService; _memberTypeService = memberTypeService; } - public IContentTypeServiceBase Create(IContentBase contentBase) + public IContentTypeBaseService For(IContentBase contentBase) { switch (contentBase) { @@ -30,6 +30,5 @@ namespace Umbraco.Core.Services.Implement throw new ArgumentException($"Invalid contentBase type: {contentBase.GetType().FullName}" , nameof(contentBase)); } } - } } diff --git a/src/Umbraco.Core/Services/Implement/ContentTypeServiceBaseOfTItemTService.cs b/src/Umbraco.Core/Services/Implement/ContentTypeServiceBaseOfTItemTService.cs index f4457e0991..3a1ad64483 100644 --- a/src/Umbraco.Core/Services/Implement/ContentTypeServiceBaseOfTItemTService.cs +++ b/src/Umbraco.Core/Services/Implement/ContentTypeServiceBaseOfTItemTService.cs @@ -8,7 +8,7 @@ namespace Umbraco.Core.Services.Implement { public abstract class ContentTypeServiceBase : ContentTypeServiceBase where TItem : class, IContentTypeComposition - where TService : class, IContentTypeServiceBase + where TService : class, IContentTypeBaseService { protected ContentTypeServiceBase(IScopeProvider provider, ILogger logger, IEventMessagesFactory eventMessagesFactory) : base(provider, logger, eventMessagesFactory) diff --git a/src/Umbraco.Core/Services/Implement/ContentTypeServiceBaseOfTRepositoryTItemTService.cs b/src/Umbraco.Core/Services/Implement/ContentTypeServiceBaseOfTRepositoryTItemTService.cs index 943d4be536..d4cb890953 100644 --- a/src/Umbraco.Core/Services/Implement/ContentTypeServiceBaseOfTRepositoryTItemTService.cs +++ b/src/Umbraco.Core/Services/Implement/ContentTypeServiceBaseOfTRepositoryTItemTService.cs @@ -13,10 +13,10 @@ using Umbraco.Core.Services.Changes; namespace Umbraco.Core.Services.Implement { - public abstract class ContentTypeServiceBase : ContentTypeServiceBase, IContentTypeServiceBase + public abstract class ContentTypeServiceBase : ContentTypeServiceBase, IContentTypeBaseService where TRepository : IContentTypeRepositoryBase where TItem : class, IContentTypeComposition - where TService : class, IContentTypeServiceBase + where TService : class, IContentTypeBaseService { private readonly IAuditRepository _auditRepository; private readonly IEntityContainerRepository _containerRepository; @@ -211,7 +211,7 @@ namespace Umbraco.Core.Services.Implement #region Get, Has, Is, Count - IContentTypeComposition IContentTypeServiceBase.Get(int id) + IContentTypeComposition IContentTypeBaseService.Get(int id) { return Get(id); } diff --git a/src/Umbraco.Core/Services/ServiceContext.cs b/src/Umbraco.Core/Services/ServiceContext.cs index efb4787e65..f3c95b07f9 100644 --- a/src/Umbraco.Core/Services/ServiceContext.cs +++ b/src/Umbraco.Core/Services/ServiceContext.cs @@ -1,5 +1,4 @@ using System; -using Umbraco.Core.Services.Implement; namespace Umbraco.Core.Services { @@ -33,12 +32,12 @@ namespace Umbraco.Core.Services private readonly Lazy _externalLoginService; private readonly Lazy _redirectUrlService; private readonly Lazy _consentService; - private readonly Lazy _contentTypeServiceBaseFactory; + private readonly Lazy _contentTypeBaseServiceProvider; /// /// Initializes a new instance of the class with lazy services. /// - public ServiceContext(Lazy publicAccessService, Lazy domainService, Lazy auditService, Lazy localizedTextService, Lazy tagService, Lazy contentService, Lazy userService, Lazy memberService, Lazy mediaService, Lazy contentTypeService, Lazy mediaTypeService, Lazy dataTypeService, Lazy fileService, Lazy localizationService, Lazy packagingService, Lazy serverRegistrationService, Lazy entityService, Lazy relationService, Lazy macroService, Lazy memberTypeService, Lazy memberGroupService, Lazy notificationService, Lazy externalLoginService, Lazy redirectUrlService, Lazy consentService, Lazy contentTypeServiceBaseFactory) + public ServiceContext(Lazy publicAccessService, Lazy domainService, Lazy auditService, Lazy localizedTextService, Lazy tagService, Lazy contentService, Lazy userService, Lazy memberService, Lazy mediaService, Lazy contentTypeService, Lazy mediaTypeService, Lazy dataTypeService, Lazy fileService, Lazy localizationService, Lazy packagingService, Lazy serverRegistrationService, Lazy entityService, Lazy relationService, Lazy macroService, Lazy memberTypeService, Lazy memberGroupService, Lazy notificationService, Lazy externalLoginService, Lazy redirectUrlService, Lazy consentService, Lazy contentTypeBaseServiceProvider) { _publicAccessService = publicAccessService; _domainService = domainService; @@ -65,7 +64,7 @@ namespace Umbraco.Core.Services _externalLoginService = externalLoginService; _redirectUrlService = redirectUrlService; _consentService = consentService; - _contentTypeServiceBaseFactory = contentTypeServiceBaseFactory; + _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider; } /// @@ -100,7 +99,7 @@ namespace Umbraco.Core.Services IServerRegistrationService serverRegistrationService = null, IRedirectUrlService redirectUrlService = null, IConsentService consentService = null, - IContentTypeServiceBaseFactory contentTypeServiceBaseFactory = null) + IContentTypeBaseServiceProvider contentTypeBaseServiceProvider = null) { Lazy Lazy(T service) => service == null ? null : new Lazy(() => service); @@ -130,7 +129,7 @@ namespace Umbraco.Core.Services Lazy(externalLoginService), Lazy(redirectUrlService), Lazy(consentService), - Lazy(contentTypeServiceBaseFactory) + Lazy(contentTypeBaseServiceProvider) ); } @@ -262,6 +261,6 @@ namespace Umbraco.Core.Services /// /// Gets the ContentTypeServiceBaseFactory. /// - public IContentTypeServiceBaseFactory ContentTypeServiceBaseFactory => _contentTypeServiceBaseFactory.Value; + public IContentTypeBaseServiceProvider ContentTypeBaseServices => _contentTypeBaseServiceProvider.Value; } } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index c0edc517c3..242b4f67bc 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -434,6 +434,7 @@ + @@ -1347,7 +1348,7 @@ - + @@ -1365,7 +1366,7 @@ - + diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs index 73554aec67..703ae3f0e7 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs @@ -124,8 +124,8 @@ namespace Umbraco.Tests.PublishedContent Mock.Get(contentTypeService).Setup(x => x.GetAll()).Returns(contentTypes); Mock.Get(contentTypeService).Setup(x => x.GetAll(It.IsAny())).Returns(contentTypes); - var contentTypeServiceBaseFactory = Mock.Of(); - Mock.Get(contentTypeServiceBaseFactory).Setup(x => x.Create(It.IsAny())).Returns(contentTypeService); + var contentTypeServiceBaseFactory = Mock.Of(); + Mock.Get(contentTypeServiceBaseFactory).Setup(x => x.For(It.IsAny())).Returns(contentTypeService); var dataTypeService = Mock.Of(); Mock.Get(dataTypeService).Setup(x => x.GetAll()).Returns(dataTypes); diff --git a/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs b/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs index d2fd3f90f9..2f0876b9ba 100644 --- a/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs +++ b/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs @@ -80,7 +80,7 @@ namespace Umbraco.Tests.Scoping var documentRepository = Mock.Of(); var mediaRepository = Mock.Of(); var memberRepository = Mock.Of(); - var contentTypeServiceBaseFactory = Current.Services.ContentTypeServiceBaseFactory; + var contentTypeServiceBaseFactory = Current.Services.ContentTypeBaseServices; return new PublishedSnapshotService( options, diff --git a/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs b/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs index 8f567afd65..94518b8dfd 100644 --- a/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs +++ b/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs @@ -53,7 +53,7 @@ namespace Umbraco.Tests.Services var documentRepository = Factory.GetInstance(); var mediaRepository = Mock.Of(); var memberRepository = Mock.Of(); - var contentTypeServiceBaseFactory = Current.Services.ContentTypeServiceBaseFactory; + var contentTypeServiceBaseFactory = Current.Services.ContentTypeBaseServices; return new PublishedSnapshotService( options, diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects.cs b/src/Umbraco.Tests/TestHelpers/TestObjects.cs index 6ab714a68a..db3aa10d44 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects.cs @@ -191,7 +191,7 @@ namespace Umbraco.Tests.TestHelpers var tagService = GetLazyService(factory, c => new TagService(scopeProvider, logger, eventMessagesFactory, GetRepo(c))); var redirectUrlService = GetLazyService(factory, c => new RedirectUrlService(scopeProvider, logger, eventMessagesFactory, GetRepo(c))); var consentService = GetLazyService(factory, c => new ConsentService(scopeProvider, logger, eventMessagesFactory, GetRepo(c))); - var contentTypeServiceBaseFactory = GetLazyService(factory, c => new ContentTypeServiceBaseFactory(factory.GetInstance(),factory.GetInstance(),factory.GetInstance())); + var contentTypeServiceBaseFactory = GetLazyService(factory, c => new ContentTypeBaseServiceProvider(factory.GetInstance(),factory.GetInstance(),factory.GetInstance())); return new ServiceContext( publicAccessService, diff --git a/src/Umbraco.Web/Editors/ContentController.cs b/src/Umbraco.Web/Editors/ContentController.cs index 0dff862d08..ee056e38f0 100644 --- a/src/Umbraco.Web/Editors/ContentController.cs +++ b/src/Umbraco.Web/Editors/ContentController.cs @@ -1838,7 +1838,7 @@ namespace Umbraco.Web.Editors throw new HttpResponseException(HttpStatusCode.NotFound); } - var contentTypeService = Services.ContentTypeServiceBaseFactory.Create(parent); + var contentTypeService = Services.ContentTypeBaseServices.For(parent); var parentContentType = contentTypeService.Get(parent.ContentTypeId); //check if the item is allowed under this one if (parentContentType.AllowedContentTypes.Select(x => x.Id).ToArray() diff --git a/src/Umbraco.Web/Editors/ContentTypeController.cs b/src/Umbraco.Web/Editors/ContentTypeController.cs index 8fc60261a1..0aa7b75143 100644 --- a/src/Umbraco.Web/Editors/ContentTypeController.cs +++ b/src/Umbraco.Web/Editors/ContentTypeController.cs @@ -403,7 +403,7 @@ namespace Umbraco.Web.Editors return Enumerable.Empty(); } - var contentTypeService = Services.ContentTypeServiceBaseFactory.Create(contentItem); + var contentTypeService = Services.ContentTypeBaseServices.For(contentItem); var contentType = contentTypeService.Get(contentItem.ContentTypeId); var ids = contentType.AllowedContentTypes.Select(x => x.Id.Value).ToArray(); diff --git a/src/Umbraco.Web/Editors/MediaController.cs b/src/Umbraco.Web/Editors/MediaController.cs index 9699bf8a71..5662680a8a 100644 --- a/src/Umbraco.Web/Editors/MediaController.cs +++ b/src/Umbraco.Web/Editors/MediaController.cs @@ -47,10 +47,10 @@ namespace Umbraco.Web.Editors [MediaControllerControllerConfiguration] public class MediaController : ContentControllerBase { - public MediaController(PropertyEditorCollection propertyEditors, IContentTypeServiceBaseFactory contentTypeServiceBaseFactory) + public MediaController(PropertyEditorCollection propertyEditors, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider) { _propertyEditors = propertyEditors ?? throw new ArgumentNullException(nameof(propertyEditors)); - _contentTypeServiceBaseFactory = contentTypeServiceBaseFactory; + _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider; } /// @@ -234,7 +234,7 @@ namespace Umbraco.Web.Editors private int[] _userStartNodes; private readonly PropertyEditorCollection _propertyEditors; - private readonly IContentTypeServiceBaseFactory _contentTypeServiceBaseFactory; + private readonly IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider; protected int[] UserStartNodes { @@ -726,7 +726,7 @@ namespace Umbraco.Web.Editors if (fs == null) throw new InvalidOperationException("Could not acquire file stream"); using (fs) { - f.SetValue(_contentTypeServiceBaseFactory, Constants.Conventions.Media.File,fileName, fs); + f.SetValue(_contentTypeBaseServiceProvider, Constants.Conventions.Media.File,fileName, fs); } var saveResult = mediaService.Save(f, Security.CurrentUser.Id); diff --git a/src/Umbraco.Web/Macros/PublishedContentHashtableConverter.cs b/src/Umbraco.Web/Macros/PublishedContentHashtableConverter.cs index 1ff38f3d1b..a871fef1b0 100644 --- a/src/Umbraco.Web/Macros/PublishedContentHashtableConverter.cs +++ b/src/Umbraco.Web/Macros/PublishedContentHashtableConverter.cs @@ -202,7 +202,7 @@ namespace Umbraco.Web.Macros CreatorName = _inner.GetCreatorProfile().Name; WriterName = _inner.GetWriterProfile().Name; - var contentTypeService = Current.Services.ContentTypeServiceBaseFactory.Create(_inner); + var contentTypeService = Current.Services.ContentTypeBaseServices.For(_inner); ContentType = Current.PublishedContentTypeFactory.CreateContentType(contentTypeService.Get(_inner.ContentTypeId)); _properties = ContentType.PropertyTypes diff --git a/src/Umbraco.Web/Models/Mapping/ContentMapperProfile.cs b/src/Umbraco.Web/Models/Mapping/ContentMapperProfile.cs index 2c13a2ecad..55b1672b2b 100644 --- a/src/Umbraco.Web/Models/Mapping/ContentMapperProfile.cs +++ b/src/Umbraco.Web/Models/Mapping/ContentMapperProfile.cs @@ -23,7 +23,7 @@ namespace Umbraco.Web.Models.Mapping IUserService userService, IContentService contentService, IContentTypeService contentTypeService, - IContentTypeServiceBaseFactory contentTypeServiceBaseFactory, + IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, ILocalizationService localizationService) { // create, capture, cache @@ -31,7 +31,7 @@ namespace Umbraco.Web.Models.Mapping var creatorResolver = new CreatorResolver(userService); var actionButtonsResolver = new ActionButtonsResolver(userService, contentService); var childOfListViewResolver = new ContentChildOfListViewResolver(contentService, contentTypeService); - var contentTypeBasicResolver = new ContentTypeBasicResolver(contentTypeServiceBaseFactory); + var contentTypeBasicResolver = new ContentTypeBasicResolver(contentTypeBaseServiceProvider); var allowedTemplatesResolver = new AllowedTemplatesResolver(contentTypeService); var defaultTemplateResolver = new DefaultTemplateResolver(); var variantResolver = new ContentVariantResolver(localizationService); diff --git a/src/Umbraco.Web/Models/Mapping/ContentTypeBasicResolver.cs b/src/Umbraco.Web/Models/Mapping/ContentTypeBasicResolver.cs index 0655f4d8cf..19c150e072 100644 --- a/src/Umbraco.Web/Models/Mapping/ContentTypeBasicResolver.cs +++ b/src/Umbraco.Web/Models/Mapping/ContentTypeBasicResolver.cs @@ -16,11 +16,11 @@ namespace Umbraco.Web.Models.Mapping internal class ContentTypeBasicResolver : IValueResolver where TSource : IContentBase { - private readonly IContentTypeServiceBaseFactory _contentTypeServiceBaseFactory; + private readonly IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider; - public ContentTypeBasicResolver(IContentTypeServiceBaseFactory contentTypeServiceBaseFactory) + public ContentTypeBasicResolver(IContentTypeBaseServiceProvider contentTypeBaseServiceProvider) { - _contentTypeServiceBaseFactory = contentTypeServiceBaseFactory; + _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider; } public ContentTypeBasic Resolve(TSource source, TDestination destination, ContentTypeBasic destMember, ResolutionContext context) @@ -30,7 +30,7 @@ namespace Umbraco.Web.Models.Mapping if (HttpContext.Current != null && UmbracoContext.Current != null && UmbracoContext.Current.Security.CurrentUser != null && UmbracoContext.Current.Security.CurrentUser.AllowedSections.Any(x => x.Equals(Constants.Applications.Settings))) { - var contentTypeService = _contentTypeServiceBaseFactory.Create(source); + var contentTypeService = _contentTypeBaseServiceProvider.For(source); var contentType = contentTypeService.Get(source.ContentTypeId); var contentTypeBasic = Mapper.Map(contentType); diff --git a/src/Umbraco.Web/Models/Mapping/MediaMapperProfile.cs b/src/Umbraco.Web/Models/Mapping/MediaMapperProfile.cs index 2b575c87da..7a8706edf2 100644 --- a/src/Umbraco.Web/Models/Mapping/MediaMapperProfile.cs +++ b/src/Umbraco.Web/Models/Mapping/MediaMapperProfile.cs @@ -25,12 +25,12 @@ namespace Umbraco.Web.Models.Mapping IMediaService mediaService, IMediaTypeService mediaTypeService, ILogger logger, - IContentTypeServiceBaseFactory contentTypeServiceBaseFactory) + IContentTypeBaseServiceProvider contentTypeBaseServiceProvider) { // create, capture, cache var mediaOwnerResolver = new OwnerResolver(userService); var childOfListViewResolver = new MediaChildOfListViewResolver(mediaService, mediaTypeService); - var mediaTypeBasicResolver = new ContentTypeBasicResolver(contentTypeServiceBaseFactory); + var mediaTypeBasicResolver = new ContentTypeBasicResolver(contentTypeBaseServiceProvider); //FROM IMedia TO MediaItemDisplay CreateMap() diff --git a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs index e6a7c24f59..f470e5a65a 100755 --- a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs +++ b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs @@ -41,7 +41,7 @@ namespace Umbraco.Web.PublishedCache.NuCache private readonly IMemberRepository _memberRepository; private readonly IGlobalSettings _globalSettings; private readonly ISiteDomainHelper _siteDomainHelper; - private readonly IContentTypeServiceBaseFactory _contentTypeServiceBaseFactory; + private readonly IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider; private readonly IEntityXmlSerializer _entitySerializer; private readonly IDefaultCultureAccessor _defaultCultureAccessor; @@ -85,7 +85,7 @@ namespace Umbraco.Web.PublishedCache.NuCache IUmbracoContextAccessor umbracoContextAccessor, ILogger logger, IScopeProvider scopeProvider, IDocumentRepository documentRepository, IMediaRepository mediaRepository, IMemberRepository memberRepository, IDefaultCultureAccessor defaultCultureAccessor, - IDataSource dataSource, IGlobalSettings globalSettings, ISiteDomainHelper siteDomainHelper, IContentTypeServiceBaseFactory contentTypeServiceBaseFactory, + IDataSource dataSource, IGlobalSettings globalSettings, ISiteDomainHelper siteDomainHelper, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IEntityXmlSerializer entitySerializer) : base(publishedSnapshotAccessor, variationContextAccessor) { @@ -104,7 +104,7 @@ namespace Umbraco.Web.PublishedCache.NuCache _defaultCultureAccessor = defaultCultureAccessor; _globalSettings = globalSettings; _siteDomainHelper = siteDomainHelper; - _contentTypeServiceBaseFactory = contentTypeServiceBaseFactory; + _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider; // we need an Xml serializer here so that the member cache can support XPath, // for members this is done by navigating the serialized-to-xml member @@ -1204,7 +1204,7 @@ namespace Umbraco.Web.PublishedCache.NuCache var cultureData = new Dictionary(); // sanitize - names should be ok but ... never knows - var contentTypeService = _contentTypeServiceBaseFactory.Create(content); + var contentTypeService = _contentTypeBaseServiceProvider.For(content); var contentType = contentTypeService.Get(content.ContentTypeId); if (contentType.VariesByCulture()) {