diff --git a/src/Umbraco.Core/Composing/Composers/ServicesComposer.cs b/src/Umbraco.Core/Composing/Composers/ServicesComposer.cs index 0410e72148..1fe5dd7561 100644 --- a/src/Umbraco.Core/Composing/Composers/ServicesComposer.cs +++ b/src/Umbraco.Core/Composing/Composers/ServicesComposer.cs @@ -37,6 +37,7 @@ namespace Umbraco.Core.Composing.Composers 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 63f9f176ea..d4ec876565 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, IContentTypeService contentTypeService, string propertyTypeAlias, string filename, Stream filestream, string culture = null, string segment = null) + public static void SetValue(this IContentBase content, IContentTypeServiceBaseFactory contentTypeServiceBaseFactory, 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,contentTypeService, propertyTypeAlias, filename, filestream, culture, segment); + SetUploadFile(content,contentTypeServiceBaseFactory, propertyTypeAlias, filename, filestream, culture, segment); } - private static void SetUploadFile(this IContentBase content, IContentTypeService contentTypeService, string propertyTypeAlias, string filename, Stream filestream, string culture = null, string segment = null) + private static void SetUploadFile(this IContentBase content, IContentTypeServiceBaseFactory contentTypeServiceBaseFactory, string propertyTypeAlias, string filename, Stream filestream, string culture = null, string segment = null) { - var property = GetProperty(content, contentTypeService, propertyTypeAlias); + var property = GetProperty(content, contentTypeServiceBaseFactory, 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,11 +201,12 @@ namespace Umbraco.Core } // gets or creates a property for a content item. - private static Property GetProperty(IContentBase content, IContentTypeService contentTypeService, string propertyTypeAlias) + private static Property GetProperty(IContentBase content, IContentTypeServiceBaseFactory contentTypeServiceBaseFactory, string propertyTypeAlias) { var property = content.Properties.FirstOrDefault(x => x.Alias.InvariantEquals(propertyTypeAlias)); if (property != null) return property; + var contentTypeService = contentTypeServiceBaseFactory.Create(content); var contentType = contentTypeService.Get(content.ContentTypeId); var propertyType = contentType.CompositionPropertyTypes .FirstOrDefault(x => x.Alias.InvariantEquals(propertyTypeAlias)); @@ -233,8 +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, IContentTypeService contentTypeService, string propertyTypeAlias, string filename, Stream filestream, string filepath) + public static string StoreFile(this IContentBase content, IContentTypeServiceBaseFactory contentTypeServiceBaseFactory, string propertyTypeAlias, string filename, Stream filestream, string filepath) { + var contentTypeService = contentTypeServiceBaseFactory.Create(content); var contentType = contentTypeService.Get(content.ContentTypeId); var propertyType = contentType .CompositionPropertyTypes.FirstOrDefault(x => x.Alias.InvariantEquals(propertyTypeAlias)); @@ -317,7 +319,7 @@ namespace Umbraco.Core { return serializer.Serialize(content, false, false); } - + /// /// Creates the xml representation for the object diff --git a/src/Umbraco.Core/Services/IContentTypeServiceBase.cs b/src/Umbraco.Core/Services/IContentTypeServiceBase.cs index bc091535d3..cd6f2f4911 100644 --- a/src/Umbraco.Core/Services/IContentTypeServiceBase.cs +++ b/src/Umbraco.Core/Services/IContentTypeServiceBase.cs @@ -4,11 +4,16 @@ using Umbraco.Core.Models; namespace Umbraco.Core.Services { + public interface IContentTypeServiceBase + { + IContentTypeComposition Get(int id); + } + /// /// Provides a common base interface for , and . /// /// The type of the item. - public interface IContentTypeServiceBase : IService + public interface IContentTypeServiceBase : IContentTypeServiceBase, IService where TItem : IContentTypeComposition { TItem Get(int id); diff --git a/src/Umbraco.Core/Services/IContentTypeServiceBaseFactory.cs b/src/Umbraco.Core/Services/IContentTypeServiceBaseFactory.cs new file mode 100644 index 0000000000..c816863128 --- /dev/null +++ b/src/Umbraco.Core/Services/IContentTypeServiceBaseFactory.cs @@ -0,0 +1,10 @@ +using Umbraco.Core.Models; + +namespace Umbraco.Core.Services +{ + public interface IContentTypeServiceBaseFactory + { + IContentTypeServiceBase Create(IContentBase contentBase); + + } +} diff --git a/src/Umbraco.Core/Services/Implement/ContentTypeServiceBaseFactory.cs b/src/Umbraco.Core/Services/Implement/ContentTypeServiceBaseFactory.cs new file mode 100644 index 0000000000..64395d4e2d --- /dev/null +++ b/src/Umbraco.Core/Services/Implement/ContentTypeServiceBaseFactory.cs @@ -0,0 +1,35 @@ +using System; +using Umbraco.Core.Models; + +namespace Umbraco.Core.Services.Implement +{ + public class ContentTypeServiceBaseFactory : IContentTypeServiceBaseFactory + { + private readonly IContentTypeService _contentTypeService; + private readonly IMediaTypeService _mediaTypeService; + private readonly IMemberTypeService _memberTypeService; + + public ContentTypeServiceBaseFactory(IContentTypeService contentTypeService, IMediaTypeService mediaTypeService, IMemberTypeService memberTypeService) + { + _contentTypeService = contentTypeService; + _mediaTypeService = mediaTypeService; + _memberTypeService = memberTypeService; + } + + public IContentTypeServiceBase Create(IContentBase contentBase) + { + switch (contentBase) + { + case IContent _: + return _contentTypeService; + case IMedia _: + return _mediaTypeService; + case IMember _: + return _memberTypeService; + default: + throw new ArgumentException($"Invalid contentBase type: {contentBase.GetType().FullName}" , nameof(contentBase)); + } + } + + } +} diff --git a/src/Umbraco.Core/Services/Implement/ContentTypeServiceBaseOfTRepositoryTItemTService.cs b/src/Umbraco.Core/Services/Implement/ContentTypeServiceBaseOfTRepositoryTItemTService.cs index 78bb9821e4..943d4be536 100644 --- a/src/Umbraco.Core/Services/Implement/ContentTypeServiceBaseOfTRepositoryTItemTService.cs +++ b/src/Umbraco.Core/Services/Implement/ContentTypeServiceBaseOfTRepositoryTItemTService.cs @@ -211,6 +211,11 @@ namespace Umbraco.Core.Services.Implement #region Get, Has, Is, Count + IContentTypeComposition IContentTypeServiceBase.Get(int id) + { + return Get(id); + } + public TItem Get(int id) { using (var scope = ScopeProvider.CreateScope(autoComplete: true)) @@ -951,5 +956,7 @@ namespace Umbraco.Core.Services.Implement } #endregion + + } } diff --git a/src/Umbraco.Core/Services/ServiceContext.cs b/src/Umbraco.Core/Services/ServiceContext.cs index 6d7ac8a5e7..efb4787e65 100644 --- a/src/Umbraco.Core/Services/ServiceContext.cs +++ b/src/Umbraco.Core/Services/ServiceContext.cs @@ -1,4 +1,5 @@ using System; +using Umbraco.Core.Services.Implement; namespace Umbraco.Core.Services { @@ -32,11 +33,12 @@ namespace Umbraco.Core.Services private readonly Lazy _externalLoginService; private readonly Lazy _redirectUrlService; private readonly Lazy _consentService; + private readonly Lazy _contentTypeServiceBaseFactory; /// /// 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) + 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) { _publicAccessService = publicAccessService; _domainService = domainService; @@ -63,6 +65,7 @@ namespace Umbraco.Core.Services _externalLoginService = externalLoginService; _redirectUrlService = redirectUrlService; _consentService = consentService; + _contentTypeServiceBaseFactory = contentTypeServiceBaseFactory; } /// @@ -96,7 +99,8 @@ namespace Umbraco.Core.Services IExternalLoginService externalLoginService = null, IServerRegistrationService serverRegistrationService = null, IRedirectUrlService redirectUrlService = null, - IConsentService consentService = null) + IConsentService consentService = null, + IContentTypeServiceBaseFactory contentTypeServiceBaseFactory = null) { Lazy Lazy(T service) => service == null ? null : new Lazy(() => service); @@ -125,7 +129,9 @@ namespace Umbraco.Core.Services Lazy(notificationService), Lazy(externalLoginService), Lazy(redirectUrlService), - Lazy(consentService)); + Lazy(consentService), + Lazy(contentTypeServiceBaseFactory) + ); } /// @@ -252,5 +258,10 @@ namespace Umbraco.Core.Services /// Gets the ConsentService. /// public IConsentService ConsentService => _consentService.Value; + + /// + /// Gets the ContentTypeServiceBaseFactory. + /// + public IContentTypeServiceBaseFactory ContentTypeServiceBaseFactory => _contentTypeServiceBaseFactory.Value; } } diff --git a/src/Umbraco.Core/Umbraco.Core.csproj b/src/Umbraco.Core/Umbraco.Core.csproj index d39247ad9e..ddfa4f9df8 100755 --- a/src/Umbraco.Core/Umbraco.Core.csproj +++ b/src/Umbraco.Core/Umbraco.Core.csproj @@ -1346,6 +1346,7 @@ + @@ -1363,6 +1364,7 @@ + diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs index 8c1caae1e0..73554aec67 100644 --- a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs +++ b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs @@ -124,6 +124,9 @@ 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 dataTypeService = Mock.Of(); Mock.Get(dataTypeService).Setup(x => x.GetAll()).Returns(dataTypes); @@ -177,7 +180,7 @@ namespace Umbraco.Tests.PublishedContent dataSource, globalSettings, new SiteDomainHelper(), - contentTypeService, + contentTypeServiceBaseFactory, Mock.Of()); // invariant is the current default diff --git a/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs b/src/Umbraco.Tests/Scoping/ScopedNuCacheTests.cs index 9333d3be18..d2fd3f90f9 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 contentTypeService = Current.Services.ContentTypeService; + var contentTypeServiceBaseFactory = Current.Services.ContentTypeServiceBaseFactory; return new PublishedSnapshotService( options, @@ -97,7 +97,7 @@ namespace Umbraco.Tests.Scoping documentRepository, mediaRepository, memberRepository, DefaultCultureAccessor, new DatabaseDataSource(), - Factory.GetInstance(), new SiteDomainHelper(), contentTypeService, + Factory.GetInstance(), new SiteDomainHelper(), contentTypeServiceBaseFactory, Factory.GetInstance()); } diff --git a/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs b/src/Umbraco.Tests/Services/ContentTypeServiceVariantsTests.cs index 0d0bdcf624..8f567afd65 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 contentTypeService = Current.Services.ContentTypeService; + var contentTypeServiceBaseFactory = Current.Services.ContentTypeServiceBaseFactory; return new PublishedSnapshotService( options, @@ -70,7 +70,7 @@ namespace Umbraco.Tests.Services documentRepository, mediaRepository, memberRepository, DefaultCultureAccessor, new DatabaseDataSource(), - Factory.GetInstance(), new SiteDomainHelper(), contentTypeService, + Factory.GetInstance(), new SiteDomainHelper(), contentTypeServiceBaseFactory, Factory.GetInstance()); } diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects.cs b/src/Umbraco.Tests/TestHelpers/TestObjects.cs index 7a9702031b..6ab714a68a 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects.cs @@ -176,7 +176,7 @@ namespace Umbraco.Tests.TestHelpers var propertyEditorCollection = new PropertyEditorCollection(new DataEditorCollection(Enumerable.Empty())); var compiledPackageXmlParser = new CompiledPackageXmlParser(new ConflictingPackageData(macroService.Value, fileService.Value)); return new PackagingService( - auditService.Value, + auditService.Value, new PackagesRepository(contentService.Value, contentTypeService.Value, dataTypeService.Value, fileService.Value, macroService.Value, localizationService.Value, new EntityXmlSerializer(contentService.Value, mediaService.Value, dataTypeService.Value, userService.Value, localizationService.Value, contentTypeService.Value, urlSegmentProviders), logger, "createdPackages.config"), new PackagesRepository(contentService.Value, contentTypeService.Value, dataTypeService.Value, fileService.Value, macroService.Value, localizationService.Value, @@ -188,9 +188,10 @@ namespace Umbraco.Tests.TestHelpers new DirectoryInfo(IOHelper.GetRootDirectorySafe()))); }); var relationService = GetLazyService(factory, c => new RelationService(scopeProvider, logger, eventMessagesFactory, entityService.Value, GetRepo(c), GetRepo(c))); - var tagService = GetLazyService(factory, c => new TagService(scopeProvider, logger, eventMessagesFactory, GetRepo(c))); + 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())); return new ServiceContext( publicAccessService, @@ -217,7 +218,8 @@ namespace Umbraco.Tests.TestHelpers notificationService, externalLoginService, redirectUrlService, - consentService); + consentService, + contentTypeServiceBaseFactory); } private Lazy GetLazyService(IFactory container, Func ctor) diff --git a/src/Umbraco.Web/Editors/ContentController.cs b/src/Umbraco.Web/Editors/ContentController.cs index b81f68f14e..0dff862d08 100644 --- a/src/Umbraco.Web/Editors/ContentController.cs +++ b/src/Umbraco.Web/Editors/ContentController.cs @@ -1838,7 +1838,8 @@ namespace Umbraco.Web.Editors throw new HttpResponseException(HttpStatusCode.NotFound); } - var parentContentType = Services.ContentTypeService.Get(parent.ContentTypeId); + var contentTypeService = Services.ContentTypeServiceBaseFactory.Create(parent); + var parentContentType = contentTypeService.Get(parent.ContentTypeId); //check if the item is allowed under this one if (parentContentType.AllowedContentTypes.Select(x => x.Id).ToArray() .Any(x => x.Value == toMove.ContentType.Id) == false) diff --git a/src/Umbraco.Web/Editors/ContentTypeController.cs b/src/Umbraco.Web/Editors/ContentTypeController.cs index a559dbe32f..8fc60261a1 100644 --- a/src/Umbraco.Web/Editors/ContentTypeController.cs +++ b/src/Umbraco.Web/Editors/ContentTypeController.cs @@ -403,7 +403,8 @@ namespace Umbraco.Web.Editors return Enumerable.Empty(); } - var contentType = Services.ContentTypeService.Get(contentItem.ContentTypeId); + var contentTypeService = Services.ContentTypeServiceBaseFactory.Create(contentItem); + var contentType = contentTypeService.Get(contentItem.ContentTypeId); var ids = contentType.AllowedContentTypes.Select(x => x.Id.Value).ToArray(); if (ids.Any() == false) return Enumerable.Empty(); @@ -498,7 +499,7 @@ namespace Umbraco.Web.Editors { return Request.CreateResponse(HttpStatusCode.NotFound); } - + var dataInstaller = new PackageDataInstallation(Logger, Services.FileService, Services.MacroService, Services.LocalizationService, Services.DataTypeService, Services.EntityService, Services.ContentTypeService, Services.ContentService, _propertyEditors); @@ -544,7 +545,7 @@ namespace Umbraco.Web.Editors } var model = new ContentTypeImportModel(); - + var file = result.FileData[0]; var fileName = file.Headers.ContentDisposition.FileName.Trim('\"'); var ext = fileName.Substring(fileName.LastIndexOf('.') + 1).ToLower(); @@ -578,6 +579,6 @@ namespace Umbraco.Web.Editors } - + } } diff --git a/src/Umbraco.Web/Editors/MediaController.cs b/src/Umbraco.Web/Editors/MediaController.cs index cdef11b6d8..9699bf8a71 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, IContentTypeService contentTypeService) + public MediaController(PropertyEditorCollection propertyEditors, IContentTypeServiceBaseFactory contentTypeServiceBaseFactory) { _propertyEditors = propertyEditors ?? throw new ArgumentNullException(nameof(propertyEditors)); - _contentTypeService = contentTypeService; + _contentTypeServiceBaseFactory = contentTypeServiceBaseFactory; } /// @@ -234,7 +234,7 @@ namespace Umbraco.Web.Editors private int[] _userStartNodes; private readonly PropertyEditorCollection _propertyEditors; - private readonly IContentTypeService _contentTypeService; + private readonly IContentTypeServiceBaseFactory _contentTypeServiceBaseFactory; 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(_contentTypeService, Constants.Conventions.Media.File,fileName, fs); + f.SetValue(_contentTypeServiceBaseFactory, 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 ece76090d8..1ff38f3d1b 100644 --- a/src/Umbraco.Web/Macros/PublishedContentHashtableConverter.cs +++ b/src/Umbraco.Web/Macros/PublishedContentHashtableConverter.cs @@ -102,7 +102,7 @@ namespace Umbraco.Web.Macros Elements.Add("path", path); Elements.Add("splitpath", path.Split(',')); } - + /// /// Puts the properties of the node into the elements table /// @@ -202,7 +202,8 @@ namespace Umbraco.Web.Macros CreatorName = _inner.GetCreatorProfile().Name; WriterName = _inner.GetWriterProfile().Name; - ContentType = Current.PublishedContentTypeFactory.CreateContentType(_inner.ContentType); + var contentTypeService = Current.Services.ContentTypeServiceBaseFactory.Create(_inner); + ContentType = Current.PublishedContentTypeFactory.CreateContentType(contentTypeService.Get(_inner.ContentTypeId)); _properties = ContentType.PropertyTypes .Select(x => diff --git a/src/Umbraco.Web/Models/Mapping/ContentMapperProfile.cs b/src/Umbraco.Web/Models/Mapping/ContentMapperProfile.cs index f6b774dae0..2c13a2ecad 100644 --- a/src/Umbraco.Web/Models/Mapping/ContentMapperProfile.cs +++ b/src/Umbraco.Web/Models/Mapping/ContentMapperProfile.cs @@ -23,6 +23,7 @@ namespace Umbraco.Web.Models.Mapping IUserService userService, IContentService contentService, IContentTypeService contentTypeService, + IContentTypeServiceBaseFactory contentTypeServiceBaseFactory, ILocalizationService localizationService) { // create, capture, cache @@ -30,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(contentTypeService); + var contentTypeBasicResolver = new ContentTypeBasicResolver(contentTypeServiceBaseFactory); 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 7b4a936676..0655f4d8cf 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 IContentTypeService _contentTypeService; + private readonly IContentTypeServiceBaseFactory _contentTypeServiceBaseFactory; - public ContentTypeBasicResolver(IContentTypeService contentTypeService) + public ContentTypeBasicResolver(IContentTypeServiceBaseFactory contentTypeServiceBaseFactory) { - _contentTypeService = contentTypeService; + _contentTypeServiceBaseFactory = contentTypeServiceBaseFactory; } public ContentTypeBasic Resolve(TSource source, TDestination destination, ContentTypeBasic destMember, ResolutionContext context) @@ -30,8 +30,9 @@ 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 contentType = _contentTypeService.Get(source.ContentTypeId); - var contentTypeBasic = Mapper.Map(contentType); + var contentTypeService = _contentTypeServiceBaseFactory.Create(source); + var contentType = contentTypeService.Get(source.ContentTypeId); + var contentTypeBasic = Mapper.Map(contentType); return contentTypeBasic; } diff --git a/src/Umbraco.Web/Models/Mapping/ContentTypeMapperProfile.cs b/src/Umbraco.Web/Models/Mapping/ContentTypeMapperProfile.cs index f70b01a422..88bf409737 100644 --- a/src/Umbraco.Web/Models/Mapping/ContentTypeMapperProfile.cs +++ b/src/Umbraco.Web/Models/Mapping/ContentTypeMapperProfile.cs @@ -134,6 +134,10 @@ namespace Umbraco.Web.Models.Mapping }); + CreateMap() + .ForMember(dest => dest.Udi, opt => opt.MapFrom(source => Udi.Create(Constants.UdiEntityType.MemberType, source.Key))) + .ForMember(dest => dest.Blueprints, opt => opt.Ignore()) + .ForMember(dest => dest.AdditionalData, opt => opt.Ignore()); CreateMap() .ForMember(dest => dest.Udi, opt => opt.MapFrom(source => Udi.Create(Constants.UdiEntityType.MemberType, source.Key))) .ForMember(dest => dest.Blueprints, opt => opt.Ignore()) diff --git a/src/Umbraco.Web/Models/Mapping/MediaMapperProfile.cs b/src/Umbraco.Web/Models/Mapping/MediaMapperProfile.cs index 4dcaaa2a0f..2b575c87da 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, - IContentTypeService contentTypeService) + IContentTypeServiceBaseFactory contentTypeServiceBaseFactory) { // create, capture, cache var mediaOwnerResolver = new OwnerResolver(userService); var childOfListViewResolver = new MediaChildOfListViewResolver(mediaService, mediaTypeService); - var mediaTypeBasicResolver = new ContentTypeBasicResolver(contentTypeService); + var mediaTypeBasicResolver = new ContentTypeBasicResolver(contentTypeServiceBaseFactory); //FROM IMedia TO MediaItemDisplay CreateMap() diff --git a/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs b/src/Umbraco.Web/PublishedCache/NuCache/PublishedSnapshotService.cs index 752cfdb5de..e6a7c24f59 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 IContentTypeService _contentTypeService; + private readonly IContentTypeServiceBaseFactory _contentTypeServiceBaseFactory; 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, IContentTypeService contentTypeService, + IDataSource dataSource, IGlobalSettings globalSettings, ISiteDomainHelper siteDomainHelper, IContentTypeServiceBaseFactory contentTypeServiceBaseFactory, IEntityXmlSerializer entitySerializer) : base(publishedSnapshotAccessor, variationContextAccessor) { @@ -104,7 +104,7 @@ namespace Umbraco.Web.PublishedCache.NuCache _defaultCultureAccessor = defaultCultureAccessor; _globalSettings = globalSettings; _siteDomainHelper = siteDomainHelper; - _contentTypeService = contentTypeService; + _contentTypeServiceBaseFactory = contentTypeServiceBaseFactory; // 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,8 @@ namespace Umbraco.Web.PublishedCache.NuCache var cultureData = new Dictionary(); // sanitize - names should be ok but ... never knows - var contentType = _contentTypeService.Get(content.ContentTypeId); + var contentTypeService = _contentTypeServiceBaseFactory.Create(content); + var contentType = contentTypeService.Get(content.ContentTypeId); if (contentType.VariesByCulture()) { var infos = content is IContent document