From 64787f85767656656d1593b2f9cfcb29cdc15ca9 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 27 Jan 2015 14:58:33 +1100 Subject: [PATCH] Fixes tests, decouples the UrlSegmentProviderResolver a little bit, removes lots of obsoleted ctors --- src/Umbraco.Core/CoreBootManager.cs | 3 +- .../ContainerManyObjectsResolver.cs | 3 +- .../Persistence/RepositoryFactory.cs | 27 ---- src/Umbraco.Core/Services/ContentService.cs | 65 +++------ .../Services/ContentTypeService.cs | 19 --- src/Umbraco.Core/Services/DataTypeService.cs | 23 ---- .../Services/EntityXmlSerializer.cs | 61 ++++++--- src/Umbraco.Core/Services/FileService.cs | 11 -- src/Umbraco.Core/Services/MacroService.cs | 18 --- src/Umbraco.Core/Services/MediaService.cs | 47 +++---- .../Services/MemberGroupService.cs | 19 --- src/Umbraco.Core/Services/MemberService.cs | 27 ---- .../Services/MemberTypeService.cs | 16 --- src/Umbraco.Core/Services/PackagingService.cs | 11 +- src/Umbraco.Core/Services/ServiceContext.cs | 64 +++++---- src/Umbraco.Core/Services/TagService.cs | 23 ---- src/Umbraco.Core/Services/UserService.cs | 17 --- .../Standalone/ServiceContextManager.cs | 4 +- .../Strings/ContentBaseExtensions.cs | 35 +++-- src/Umbraco.Tests/Models/ContentXmlTest.cs | 6 +- src/Umbraco.Tests/Models/MediaXmlTest.cs | 6 +- src/Umbraco.Tests/Mvc/UmbracoViewPageTests.cs | 47 +------ .../Persistence/BaseTableByTableTest.cs | 3 +- .../Repositories/StylesheetRepositoryTest.cs | 2 + .../Routing/UrlRoutingTestBase.cs | 2 +- ...CheckboxList-Content-Package-LegacyIds.xml | 76 ----------- .../Importing/ImportResources.Designer.cs | 30 +---- .../Services/Importing/ImportResources.resx | 3 - .../Services/Importing/PackageImportTests.cs | 6 +- .../Services/ThreadSafetyServiceTest.cs | 4 +- .../Strings/DefaultShortStringHelperTests.cs | 4 +- .../TestHelpers/BaseDatabaseFactoryTest.cs | 3 +- .../TestHelpers/BaseDatabaseTest.cs | 3 +- .../TestHelpers/BaseUmbracoApplicationTest.cs | 9 +- src/Umbraco.Tests/TestHelpers/BaseWebTest.cs | 2 +- src/Umbraco.Tests/TestHelpers/MockHelper.cs | 30 +---- src/Umbraco.Tests/Umbraco.Tests.csproj | 3 - .../UmbracoExamine/IndexInitializer.cs | 2 + .../Standalone/ServiceContextManager.cs | 4 +- src/Umbraco.Web/WebBootManager.cs | 2 + .../umbraco.presentation/library.cs | 4 +- src/UmbracoExamine/UmbracoContentIndexer.cs | 86 +++++------- src/UmbracoExamine/UmbracoMemberIndexer.cs | 124 +++++++++--------- 43 files changed, 281 insertions(+), 673 deletions(-) delete mode 100644 src/Umbraco.Tests/Services/Importing/CheckboxList-Content-Package-LegacyIds.xml diff --git a/src/Umbraco.Core/CoreBootManager.cs b/src/Umbraco.Core/CoreBootManager.cs index 550c02ea19..3afbe65e12 100644 --- a/src/Umbraco.Core/CoreBootManager.cs +++ b/src/Umbraco.Core/CoreBootManager.cs @@ -153,7 +153,8 @@ namespace Umbraco.Core factory.GetInstance(), factory.GetInstance(), factory.GetInstance(), - factory.GetInstance())); + factory.GetInstance(), + factory.GetAllInstances())); container.Register(new PerContainerLifetime()); container.Register(factory => FileSystemProviderManager.Current.GetFileSystemProvider()); } diff --git a/src/Umbraco.Core/ObjectResolution/ContainerManyObjectsResolver.cs b/src/Umbraco.Core/ObjectResolution/ContainerManyObjectsResolver.cs index 244367b718..13cfd27c2f 100644 --- a/src/Umbraco.Core/ObjectResolution/ContainerManyObjectsResolver.cs +++ b/src/Umbraco.Core/ObjectResolution/ContainerManyObjectsResolver.cs @@ -55,9 +55,8 @@ namespace Umbraco.Core.ObjectResolution internal ContainerManyObjectsResolver(IServiceContainer container, ILogger logger, IEnumerable types, ObjectLifetimeScope scope = ObjectLifetimeScope.Application) : base(logger, types, scope) { + if (container == null) throw new ArgumentNullException("container"); _container = container; - - Resolution.Frozen += Resolution_Frozen; } diff --git a/src/Umbraco.Core/Persistence/RepositoryFactory.cs b/src/Umbraco.Core/Persistence/RepositoryFactory.cs index 2afe184b3a..60c3e4772b 100644 --- a/src/Umbraco.Core/Persistence/RepositoryFactory.cs +++ b/src/Umbraco.Core/Persistence/RepositoryFactory.cs @@ -35,33 +35,6 @@ namespace Umbraco.Core.Persistence _settings = settings; } - [Obsolete("Use the ctor specifying all dependencies instead")] - public RepositoryFactory() - : this(ApplicationContext.Current.ApplicationCache, LoggerResolver.Current.Logger, SqlSyntaxContext.SqlSyntaxProvider, UmbracoConfig.For.UmbracoSettings()) - { - } - - [Obsolete("Use the ctor specifying all dependencies instead")] - public RepositoryFactory(CacheHelper cacheHelper) - : this(cacheHelper, LoggerResolver.Current.Logger, SqlSyntaxContext.SqlSyntaxProvider, UmbracoConfig.For.UmbracoSettings()) - { - } - - [Obsolete("Use the ctor specifying all dependencies instead, NOTE: disableAllCache has zero effect")] - public RepositoryFactory(bool disableAllCache, CacheHelper cacheHelper) - : this(cacheHelper, LoggerResolver.Current.Logger, SqlSyntaxContext.SqlSyntaxProvider, UmbracoConfig.For.UmbracoSettings()) - { - if (cacheHelper == null) throw new ArgumentNullException("cacheHelper"); - _cacheHelper = cacheHelper; - } - - [Obsolete("Use the ctor specifying all dependencies instead")] - public RepositoryFactory(bool disableAllCache) - : this(disableAllCache ? CacheHelper.CreateDisabledCacheHelper() : ApplicationContext.Current.ApplicationCache, LoggerResolver.Current.Logger, SqlSyntaxContext.SqlSyntaxProvider, UmbracoConfig.For.UmbracoSettings()) - { - } - - #endregion public virtual ITaskRepository CreateTaskRepository(IDatabaseUnitOfWork uow) diff --git a/src/Umbraco.Core/Services/ContentService.cs b/src/Umbraco.Core/Services/ContentService.cs index c4181a80a4..d9c9c71d3b 100644 --- a/src/Umbraco.Core/Services/ContentService.cs +++ b/src/Umbraco.Core/Services/ContentService.cs @@ -19,6 +19,7 @@ using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Core.Persistence.UnitOfWork; using Umbraco.Core.Publishing; +using Umbraco.Core.Strings; namespace Umbraco.Core.Services { @@ -32,49 +33,23 @@ namespace Umbraco.Core.Services private readonly EntityXmlSerializer _entitySerializer = new EntityXmlSerializer(); private readonly IDataTypeService _dataTypeService; private readonly IUserService _userService; + private readonly IEnumerable _urlSegmentProviders; //Support recursive locks because some of the methods that require locking call other methods that require locking. //for example, the Move method needs to be locked but this calls the Save method which also needs to be locked. private static readonly ReaderWriterLockSlim Locker = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); - [Obsolete("Use the constructors that specify all dependencies instead")] - public ContentService() - : this(new RepositoryFactory(ApplicationContext.Current.ApplicationCache, LoggerResolver.Current.Logger, SqlSyntaxContext.SqlSyntaxProvider, UmbracoConfig.For.UmbracoSettings())) - { } - - [Obsolete("Use the constructors that specify all dependencies instead")] - public ContentService(RepositoryFactory repositoryFactory) - : this(new PetaPocoUnitOfWorkProvider(LoggerResolver.Current.Logger), repositoryFactory, new PublishingStrategy()) - { } - - [Obsolete("Use the constructors that specify all dependencies instead")] - public ContentService(IDatabaseUnitOfWorkProvider provider) - : this(provider, new RepositoryFactory(ApplicationContext.Current.ApplicationCache, LoggerResolver.Current.Logger, SqlSyntaxContext.SqlSyntaxProvider, UmbracoConfig.For.UmbracoSettings()), new PublishingStrategy()) - { } - - [Obsolete("Use the constructors that specify all dependencies instead")] - public ContentService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory) - : this(provider, repositoryFactory, new PublishingStrategy()) - { } - - [Obsolete("Use the constructors that specify all dependencies instead")] - public ContentService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, IPublishingStrategy publishingStrategy) - : base(provider, repositoryFactory, LoggerResolver.Current.Logger) - { - if (publishingStrategy == null) throw new ArgumentNullException("publishingStrategy"); - _dataTypeService = new DataTypeService(UowProvider, RepositoryFactory); - _userService = new UserService(UowProvider, RepositoryFactory); - } - - public ContentService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IPublishingStrategy publishingStrategy, IDataTypeService dataTypeService, IUserService userService) + public ContentService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IPublishingStrategy publishingStrategy, IDataTypeService dataTypeService, IUserService userService, IEnumerable urlSegmentProviders) : base(provider, repositoryFactory, logger) { if (publishingStrategy == null) throw new ArgumentNullException("publishingStrategy"); if (dataTypeService == null) throw new ArgumentNullException("dataTypeService"); if (userService == null) throw new ArgumentNullException("userService"); + if (urlSegmentProviders == null) throw new ArgumentNullException("urlSegmentProviders"); _publishingStrategy = publishingStrategy; _dataTypeService = dataTypeService; _userService = userService; + _urlSegmentProviders = urlSegmentProviders; } public int CountPublished(string contentTypeAlias = null) @@ -270,7 +245,7 @@ namespace Umbraco.Core.Services content.WriterId = userId; repository.AddOrUpdate(content); //Generate a new preview - repository.AddOrUpdatePreviewXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, c)); + repository.AddOrUpdatePreviewXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, c)); uow.Commit(); } @@ -322,7 +297,7 @@ namespace Umbraco.Core.Services content.WriterId = userId; repository.AddOrUpdate(content); //Generate a new preview - repository.AddOrUpdatePreviewXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, c)); + repository.AddOrUpdatePreviewXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, c)); uow.Commit(); } @@ -945,7 +920,7 @@ namespace Umbraco.Core.Services repository.AddOrUpdate(content); //add or update preview - repository.AddOrUpdatePreviewXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, c)); + repository.AddOrUpdatePreviewXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, c)); } } else @@ -955,7 +930,7 @@ namespace Umbraco.Core.Services content.WriterId = userId; repository.AddOrUpdate(content); //add or update preview - repository.AddOrUpdatePreviewXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, c)); + repository.AddOrUpdatePreviewXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, c)); } } @@ -1293,7 +1268,7 @@ namespace Umbraco.Core.Services repository.AddOrUpdate(copy); //add or update a preview - repository.AddOrUpdatePreviewXml(copy, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, c)); + repository.AddOrUpdatePreviewXml(copy, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, c)); uow.Commit(); @@ -1379,7 +1354,7 @@ namespace Umbraco.Core.Services repository.AddOrUpdate(content); //add or update a preview - repository.AddOrUpdatePreviewXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, c)); + repository.AddOrUpdatePreviewXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, c)); uow.Commit(); } @@ -1445,13 +1420,13 @@ namespace Umbraco.Core.Services repository.AddOrUpdate(content); //add or update a preview - repository.AddOrUpdatePreviewXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, c)); + repository.AddOrUpdatePreviewXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, c)); } foreach (var content in shouldBePublished) { //Create and Save ContentXml DTO - repository.AddOrUpdateContentXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, c)); + repository.AddOrUpdateContentXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, c)); } uow.Commit(); @@ -1482,7 +1457,7 @@ namespace Umbraco.Core.Services using (var repository = RepositoryFactory.CreateContentRepository(uow)) { repository.RebuildXmlStructures( - content => _entitySerializer.Serialize(this, _dataTypeService, _userService, content), + content => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, content), contentTypeIds: contentTypeIds.Length == 0 ? null : contentTypeIds); uow.Commit(); @@ -1571,7 +1546,7 @@ namespace Umbraco.Core.Services // change how this method calls "Save" as it needs to save using an internal method using (var uow = UowProvider.GetUnitOfWork()) { - var xml = _entitySerializer.Serialize(this, _dataTypeService, _userService, content); + var xml = _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, content); var poco = new ContentXmlDto { NodeId = content.Id, Xml = xml.ToString(SaveOptions.None) }; var exists = @@ -1670,9 +1645,9 @@ namespace Umbraco.Core.Services item.Result.ContentItem.WriterId = userId; repository.AddOrUpdate(item.Result.ContentItem); //add or update a preview - repository.AddOrUpdatePreviewXml(item.Result.ContentItem, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, c)); + repository.AddOrUpdatePreviewXml(item.Result.ContentItem, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, c)); //add or update the published xml - repository.AddOrUpdateContentXml(item.Result.ContentItem, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, c)); + repository.AddOrUpdateContentXml(item.Result.ContentItem, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, c)); updated.Add(item.Result.ContentItem); } @@ -1789,12 +1764,12 @@ namespace Umbraco.Core.Services repository.AddOrUpdate(content); //Generate a new preview - repository.AddOrUpdatePreviewXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, c)); + repository.AddOrUpdatePreviewXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, c)); if (published) { //Content Xml - repository.AddOrUpdateContentXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, c)); + repository.AddOrUpdateContentXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, c)); } uow.Commit(); @@ -1856,7 +1831,7 @@ namespace Umbraco.Core.Services repository.AddOrUpdate(content); //Generate a new preview - repository.AddOrUpdatePreviewXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, c)); + repository.AddOrUpdatePreviewXml(content, c => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, c)); uow.Commit(); } diff --git a/src/Umbraco.Core/Services/ContentTypeService.cs b/src/Umbraco.Core/Services/ContentTypeService.cs index 9bff23a99b..9c88089cd2 100644 --- a/src/Umbraco.Core/Services/ContentTypeService.cs +++ b/src/Umbraco.Core/Services/ContentTypeService.cs @@ -32,25 +32,6 @@ namespace Umbraco.Core.Services //for example, the Move method needs to be locked but this calls the Save method which also needs to be locked. private static readonly ReaderWriterLockSlim Locker = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion); - [Obsolete("Use the constructors that specify all dependencies instead")] - public ContentTypeService(IContentService contentService, IMediaService mediaService) - : this(new PetaPocoUnitOfWorkProvider(LoggerResolver.Current.Logger), new RepositoryFactory(), contentService, mediaService) - {} - - [Obsolete("Use the constructors that specify all dependencies instead")] - public ContentTypeService( RepositoryFactory repositoryFactory, IContentService contentService, IMediaService mediaService) - : this(new PetaPocoUnitOfWorkProvider(), repositoryFactory, contentService, mediaService) - { } - - [Obsolete("Use the constructors that specify all dependencies instead")] - public ContentTypeService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, IContentService contentService, IMediaService mediaService) - : base(provider, repositoryFactory, LoggerResolver.Current.Logger) - { - if (contentService == null) throw new ArgumentNullException("contentService"); - if (mediaService == null) throw new ArgumentNullException("mediaService"); - _contentService = contentService; - _mediaService = mediaService; - } public ContentTypeService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IContentService contentService, IMediaService mediaService) : base(provider, repositoryFactory, logger) diff --git a/src/Umbraco.Core/Services/DataTypeService.cs b/src/Umbraco.Core/Services/DataTypeService.cs index f42dfeddcf..84437e79f4 100644 --- a/src/Umbraco.Core/Services/DataTypeService.cs +++ b/src/Umbraco.Core/Services/DataTypeService.cs @@ -21,29 +21,6 @@ namespace Umbraco.Core.Services public class DataTypeService : RepositoryService, IDataTypeService { - [Obsolete("Use the constructors that specify all dependencies instead")] - public DataTypeService() - : this(new RepositoryFactory()) - {} - - [Obsolete("Use the constructors that specify all dependencies instead")] - public DataTypeService(RepositoryFactory repositoryFactory) - : this(new PetaPocoUnitOfWorkProvider(), repositoryFactory) - { - } - - [Obsolete("Use the constructors that specify all dependencies instead")] - public DataTypeService(IDatabaseUnitOfWorkProvider provider) - : this(provider, new RepositoryFactory()) - { - } - - [Obsolete("Use the constructors that specify all dependencies instead")] - public DataTypeService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory) - : this(provider, repositoryFactory, LoggerResolver.Current.Logger) - { - } - public DataTypeService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger) : base(provider, repositoryFactory, logger) { diff --git a/src/Umbraco.Core/Services/EntityXmlSerializer.cs b/src/Umbraco.Core/Services/EntityXmlSerializer.cs index 949b4e61c7..845277b8af 100644 --- a/src/Umbraco.Core/Services/EntityXmlSerializer.cs +++ b/src/Umbraco.Core/Services/EntityXmlSerializer.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using System.Globalization; using System.Linq; @@ -26,14 +27,26 @@ namespace Umbraco.Core.Services /// /// /// Content to export + /// /// Optional parameter indicating whether to include descendents /// containing the xml representation of the Content object - public XElement Serialize(IContentService contentService, IDataTypeService dataTypeService, IUserService userService, IContent content, bool deep = false) + public XElement Serialize( + IContentService contentService, + IDataTypeService dataTypeService, + IUserService userService, + IEnumerable urlSegmentProviders, + IContent content, + bool deep = false) { + if (contentService == null) throw new ArgumentNullException("contentService"); + if (dataTypeService == null) throw new ArgumentNullException("dataTypeService"); + if (userService == null) throw new ArgumentNullException("userService"); + if (content == null) throw new ArgumentNullException("content"); + if (urlSegmentProviders == null) throw new ArgumentNullException("urlSegmentProviders"); //nodeName should match Casing.SafeAliasWithForcingCheck(content.ContentType.Alias); var nodeName = UmbracoConfig.For.UmbracoSettings().Content.UseLegacyXmlSchema ? "node" : content.ContentType.Alias.ToSafeAliasWithForcingCheck(); - var xml = Serialize(dataTypeService, content, nodeName); + var xml = Serialize(dataTypeService, content, content.GetUrlSegment(urlSegmentProviders), nodeName); xml.Add(new XAttribute("nodeType", content.ContentType.Id)); xml.Add(new XAttribute("creatorName", content.GetCreatorProfile(userService).Name)); xml.Add(new XAttribute("writerName", content.GetWriterProfile(userService).Name)); @@ -45,7 +58,7 @@ namespace Umbraco.Core.Services { var descendants = contentService.GetDescendants(content).ToArray(); var currentChildren = descendants.Where(x => x.ParentId == content.Id); - AddChildXml(contentService, dataTypeService, userService, descendants, currentChildren, xml); + AddChildXml(contentService, dataTypeService, userService, urlSegmentProviders, descendants, currentChildren, xml); } return xml; @@ -58,14 +71,26 @@ namespace Umbraco.Core.Services /// /// /// Media to export + /// /// Optional parameter indicating whether to include descendents /// containing the xml representation of the Media object - public XElement Serialize(IMediaService mediaService, IDataTypeService dataTypeService, IUserService userService, IMedia media, bool deep = false) + public XElement Serialize( + IMediaService mediaService, + IDataTypeService dataTypeService, + IUserService userService, + IEnumerable urlSegmentProviders, + IMedia media, + bool deep = false) { + if (mediaService == null) throw new ArgumentNullException("mediaService"); + if (dataTypeService == null) throw new ArgumentNullException("dataTypeService"); + if (userService == null) throw new ArgumentNullException("userService"); + if (media == null) throw new ArgumentNullException("media"); + if (urlSegmentProviders == null) throw new ArgumentNullException("urlSegmentProviders"); //nodeName should match Casing.SafeAliasWithForcingCheck(content.ContentType.Alias); var nodeName = UmbracoConfig.For.UmbracoSettings().Content.UseLegacyXmlSchema ? "node" : media.ContentType.Alias.ToSafeAliasWithForcingCheck(); - var xml = Serialize(dataTypeService, media, nodeName); + var xml = Serialize(dataTypeService, media, media.GetUrlSegment(urlSegmentProviders), nodeName); xml.Add(new XAttribute("nodeType", media.ContentType.Id)); xml.Add(new XAttribute("writerName", media.GetCreatorProfile(userService).Name)); xml.Add(new XAttribute("writerID", media.CreatorId)); @@ -77,7 +102,7 @@ namespace Umbraco.Core.Services { var descendants = mediaService.GetDescendants(media).ToArray(); var currentChildren = descendants.Where(x => x.ParentId == media.Id); - AddChildXml(mediaService, dataTypeService, userService, descendants, currentChildren, xml); + AddChildXml(mediaService, dataTypeService, userService, urlSegmentProviders, descendants, currentChildren, xml); } return xml; @@ -94,7 +119,7 @@ namespace Umbraco.Core.Services //nodeName should match Casing.SafeAliasWithForcingCheck(content.ContentType.Alias); var nodeName = UmbracoConfig.For.UmbracoSettings().Content.UseLegacyXmlSchema ? "node" : member.ContentType.Alias.ToSafeAliasWithForcingCheck(); - var xml = Serialize(dataTypeService, member, nodeName); + var xml = Serialize(dataTypeService, member, "", nodeName); xml.Add(new XAttribute("nodeType", member.ContentType.Id)); xml.Add(new XAttribute("nodeTypeAlias", member.ContentType.Alias)); @@ -407,22 +432,23 @@ namespace Umbraco.Core.Services /// /// /// + /// /// /// /// - private void AddChildXml(IMediaService mediaService, IDataTypeService dataTypeService, IUserService userService, IMedia[] originalDescendants, IEnumerable currentChildren, XElement currentXml) + private void AddChildXml(IMediaService mediaService, IDataTypeService dataTypeService, IUserService userService, IEnumerable urlSegmentProviders, IMedia[] originalDescendants, IEnumerable currentChildren, XElement currentXml) { foreach (var child in currentChildren) { //add the child's xml - var childXml = Serialize(mediaService, dataTypeService, userService, child); + var childXml = Serialize(mediaService, dataTypeService, userService, urlSegmentProviders, child); currentXml.Add(childXml); //copy local (out of closure) var c = child; //get this item's children var children = originalDescendants.Where(x => x.ParentId == c.Id); //recurse and add it's children to the child xml element - AddChildXml(mediaService, dataTypeService, userService, originalDescendants, children, childXml); + AddChildXml(mediaService, dataTypeService, userService, urlSegmentProviders, originalDescendants, children, childXml); } } @@ -431,13 +457,11 @@ namespace Umbraco.Core.Services /// /// /// Base Content or Media to export + /// /// Name of the node /// - private XElement Serialize(IDataTypeService dataTypeService, IContentBase contentBase, string nodeName) + private XElement Serialize(IDataTypeService dataTypeService, IContentBase contentBase, string urlValue, string nodeName) { - //NOTE: that one will take care of umbracoUrlName - var url = contentBase.GetUrlSegment(); - var xml = new XElement(nodeName, new XAttribute("id", contentBase.Id), new XAttribute("parentID", contentBase.Level > 1 ? contentBase.ParentId : -1), @@ -447,7 +471,7 @@ namespace Umbraco.Core.Services new XAttribute("createDate", contentBase.CreateDate.ToString("s")), new XAttribute("updateDate", contentBase.UpdateDate.ToString("s")), new XAttribute("nodeName", contentBase.Name), - new XAttribute("urlName", url), + new XAttribute("urlName", urlValue), new XAttribute("path", contentBase.Path), new XAttribute("isDoc", "")); @@ -465,22 +489,23 @@ namespace Umbraco.Core.Services /// /// /// + /// /// /// /// - private void AddChildXml(IContentService contentService, IDataTypeService dataTypeService, IUserService userService, IContent[] originalDescendants, IEnumerable currentChildren, XElement currentXml) + private void AddChildXml(IContentService contentService, IDataTypeService dataTypeService, IUserService userService, IEnumerable urlSegmentProviders, IContent[] originalDescendants, IEnumerable currentChildren, XElement currentXml) { foreach (var child in currentChildren) { //add the child's xml - var childXml = Serialize(contentService, dataTypeService, userService, child); + var childXml = Serialize(contentService, dataTypeService, userService, urlSegmentProviders, child); currentXml.Add(childXml); //copy local (out of closure) var c = child; //get this item's children var children = originalDescendants.Where(x => x.ParentId == c.Id); //recurse and add it's children to the child xml element - AddChildXml(contentService, dataTypeService, userService, originalDescendants, children, childXml); + AddChildXml(contentService, dataTypeService, userService, urlSegmentProviders, originalDescendants, children, childXml); } } } diff --git a/src/Umbraco.Core/Services/FileService.cs b/src/Umbraco.Core/Services/FileService.cs index 29ccfbf6bf..d4e8479c47 100644 --- a/src/Umbraco.Core/Services/FileService.cs +++ b/src/Umbraco.Core/Services/FileService.cs @@ -31,17 +31,6 @@ namespace Umbraco.Core.Services private const string PartialViewHeader = "@inherits Umbraco.Web.Mvc.UmbracoTemplatePage"; private const string PartialViewMacroHeader = "@inherits Umbraco.Web.Macros.PartialViewMacroPage"; - [Obsolete("Use the constructors that specify all dependencies instead")] - public FileService() - : this(new RepositoryFactory()) - { } - - [Obsolete("Use the constructors that specify all dependencies instead")] - public FileService(RepositoryFactory repositoryFactory) - : this(new FileUnitOfWorkProvider(), new PetaPocoUnitOfWorkProvider(), repositoryFactory) - { - } - public FileService(IUnitOfWorkProvider fileProvider, IDatabaseUnitOfWorkProvider dataProvider, RepositoryFactory repositoryFactory) { if (fileProvider == null) throw new ArgumentNullException("fileProvider"); diff --git a/src/Umbraco.Core/Services/MacroService.cs b/src/Umbraco.Core/Services/MacroService.cs index b9cb1901e0..0b51850618 100644 --- a/src/Umbraco.Core/Services/MacroService.cs +++ b/src/Umbraco.Core/Services/MacroService.cs @@ -20,24 +20,6 @@ namespace Umbraco.Core.Services public class MacroService : RepositoryService, IMacroService { - [Obsolete("Use the constructors that specify all dependencies instead")] - public MacroService() - : this(new PetaPocoUnitOfWorkProvider(), new RepositoryFactory()) - { - } - - [Obsolete("Use the constructors that specify all dependencies instead")] - public MacroService(IDatabaseUnitOfWorkProvider provider) - : this(provider, new RepositoryFactory()) - { - } - - [Obsolete("Use the constructors that specify all dependencies instead")] - public MacroService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory) - : this(provider, repositoryFactory, LoggerResolver.Current.Logger) - { - } - public MacroService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger) : base(provider, repositoryFactory, logger) { diff --git a/src/Umbraco.Core/Services/MediaService.cs b/src/Umbraco.Core/Services/MediaService.cs index 2c4546479b..728d698471 100644 --- a/src/Umbraco.Core/Services/MediaService.cs +++ b/src/Umbraco.Core/Services/MediaService.cs @@ -18,6 +18,7 @@ using Umbraco.Core.Persistence.Repositories; using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Core.Persistence.UnitOfWork; using Umbraco.Core.Publishing; +using Umbraco.Core.Strings; namespace Umbraco.Core.Services { @@ -34,34 +35,18 @@ namespace Umbraco.Core.Services private readonly EntityXmlSerializer _entitySerializer = new EntityXmlSerializer(); private readonly IDataTypeService _dataTypeService; private readonly IUserService _userService; + private readonly IEnumerable _urlSegmentProviders; - [Obsolete("Use the constructors that specify all dependencies instead")] - public MediaService(RepositoryFactory repositoryFactory) - : this(new PetaPocoUnitOfWorkProvider(), repositoryFactory) - { - } - [Obsolete("Use the constructors that specify all dependencies instead")] - public MediaService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory) - : base(provider, repositoryFactory, LoggerResolver.Current.Logger) - { - _dataTypeService = new DataTypeService(provider, repositoryFactory); - _userService = new UserService(provider, repositoryFactory); - } - - [Obsolete("Use the constructors that specify all dependencies instead")] - public MediaService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, IDataTypeService dataTypeService, IUserService userService) - : this(provider, repositoryFactory, LoggerResolver.Current.Logger, dataTypeService, userService) - { - } - - public MediaService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IDataTypeService dataTypeService, IUserService userService) + public MediaService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IDataTypeService dataTypeService, IUserService userService, IEnumerable urlSegmentProviders) : base(provider, repositoryFactory, logger) { if (dataTypeService == null) throw new ArgumentNullException("dataTypeService"); if (userService == null) throw new ArgumentNullException("userService"); + if (urlSegmentProviders == null) throw new ArgumentNullException("urlSegmentProviders"); _dataTypeService = dataTypeService; _userService = userService; + _urlSegmentProviders = urlSegmentProviders; } /// @@ -169,11 +154,11 @@ namespace Umbraco.Core.Services media.CreatorId = userId; repository.AddOrUpdate(media); - repository.AddOrUpdateContentXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, m)); + repository.AddOrUpdateContentXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, m)); // generate preview for blame history? if (UmbracoConfig.For.UmbracoSettings().Content.GlobalPreviewStorageEnabled) { - repository.AddOrUpdatePreviewXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, m)); + repository.AddOrUpdatePreviewXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, m)); } uow.Commit(); @@ -225,11 +210,11 @@ namespace Umbraco.Core.Services { media.CreatorId = userId; repository.AddOrUpdate(media); - repository.AddOrUpdateContentXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, m)); + repository.AddOrUpdateContentXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, m)); // generate preview for blame history? if (UmbracoConfig.For.UmbracoSettings().Content.GlobalPreviewStorageEnabled) { - repository.AddOrUpdatePreviewXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, m)); + repository.AddOrUpdatePreviewXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, m)); } uow.Commit(); @@ -943,11 +928,11 @@ namespace Umbraco.Core.Services { media.CreatorId = userId; repository.AddOrUpdate(media); - repository.AddOrUpdateContentXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, m)); + repository.AddOrUpdateContentXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, m)); // generate preview for blame history? if (UmbracoConfig.For.UmbracoSettings().Content.GlobalPreviewStorageEnabled) { - repository.AddOrUpdatePreviewXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, m)); + repository.AddOrUpdatePreviewXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, m)); } uow.Commit(); @@ -982,11 +967,11 @@ namespace Umbraco.Core.Services { media.CreatorId = userId; repository.AddOrUpdate(media); - repository.AddOrUpdateContentXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, m)); + repository.AddOrUpdateContentXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, m)); // generate preview for blame history? if (UmbracoConfig.For.UmbracoSettings().Content.GlobalPreviewStorageEnabled) { - repository.AddOrUpdatePreviewXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, m)); + repository.AddOrUpdatePreviewXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, m)); } } @@ -1037,11 +1022,11 @@ namespace Umbraco.Core.Services i++; repository.AddOrUpdate(media); - repository.AddOrUpdateContentXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, m)); + repository.AddOrUpdateContentXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, m)); // generate preview for blame history? if (UmbracoConfig.For.UmbracoSettings().Content.GlobalPreviewStorageEnabled) { - repository.AddOrUpdatePreviewXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, m)); + repository.AddOrUpdatePreviewXml(media, m => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, m)); } } @@ -1069,7 +1054,7 @@ namespace Umbraco.Core.Services using (var repository = RepositoryFactory.CreateMediaRepository(uow)) { repository.RebuildXmlStructures( - media => _entitySerializer.Serialize(this, _dataTypeService, _userService, media), + media => _entitySerializer.Serialize(this, _dataTypeService, _userService, _urlSegmentProviders, media), contentTypeIds: contentTypeIds.Length == 0 ? null : contentTypeIds); } diff --git a/src/Umbraco.Core/Services/MemberGroupService.cs b/src/Umbraco.Core/Services/MemberGroupService.cs index 0f75bec93e..2d6ba91d6f 100644 --- a/src/Umbraco.Core/Services/MemberGroupService.cs +++ b/src/Umbraco.Core/Services/MemberGroupService.cs @@ -13,25 +13,6 @@ namespace Umbraco.Core.Services { public class MemberGroupService : RepositoryService, IMemberGroupService { - - [Obsolete("Use the constructors that specify all dependencies instead")] - public MemberGroupService(RepositoryFactory repositoryFactory) - : this(new PetaPocoUnitOfWorkProvider(), repositoryFactory) - { - } - - [Obsolete("Use the constructors that specify all dependencies instead")] - public MemberGroupService(IDatabaseUnitOfWorkProvider provider) - : this(provider, new RepositoryFactory()) - { - } - - [Obsolete("Use the constructors that specify all dependencies instead")] - public MemberGroupService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory) - : this(provider, repositoryFactory, LoggerResolver.Current.Logger) - { - } - public MemberGroupService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger) : base(provider, repositoryFactory, logger) { diff --git a/src/Umbraco.Core/Services/MemberService.cs b/src/Umbraco.Core/Services/MemberService.cs index 2bb1643b71..7b6deb3ea3 100644 --- a/src/Umbraco.Core/Services/MemberService.cs +++ b/src/Umbraco.Core/Services/MemberService.cs @@ -30,33 +30,6 @@ namespace Umbraco.Core.Services private readonly IDataTypeService _dataTypeService; private static readonly ReaderWriterLockSlim Locker = new ReaderWriterLockSlim(); - [Obsolete("Use the constructors that specify all dependencies instead")] - public MemberService(RepositoryFactory repositoryFactory, IMemberGroupService memberGroupService) - : this(new PetaPocoUnitOfWorkProvider(), repositoryFactory, memberGroupService) - { - } - - [Obsolete("Use the constructors that specify all dependencies instead")] - public MemberService(IDatabaseUnitOfWorkProvider provider, IMemberGroupService memberGroupService) - : this(provider, new RepositoryFactory(), memberGroupService) - { - } - - [Obsolete("Use the constructors that specify all dependencies instead")] - public MemberService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, IMemberGroupService memberGroupService) - : base(provider, repositoryFactory, LoggerResolver.Current.Logger) - { - if (memberGroupService == null) throw new ArgumentNullException("memberGroupService"); - _memberGroupService = memberGroupService; - _dataTypeService = new DataTypeService(provider, repositoryFactory); - } - - [Obsolete("Use the constructors that specify all dependencies instead")] - public MemberService(IDatabaseUnitOfWorkProvider provider, IMemberGroupService memberGroupService, IDataTypeService dataTypeService) - : this(provider, new RepositoryFactory(), LoggerResolver.Current.Logger, memberGroupService, dataTypeService) - { - - } public MemberService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IMemberGroupService memberGroupService, IDataTypeService dataTypeService) : base(provider, repositoryFactory, logger) diff --git a/src/Umbraco.Core/Services/MemberTypeService.cs b/src/Umbraco.Core/Services/MemberTypeService.cs index 022b8721ef..68333f4282 100644 --- a/src/Umbraco.Core/Services/MemberTypeService.cs +++ b/src/Umbraco.Core/Services/MemberTypeService.cs @@ -18,22 +18,6 @@ namespace Umbraco.Core.Services private static readonly ReaderWriterLockSlim Locker = new ReaderWriterLockSlim(); - [Obsolete("Use the constructors that specify all dependencies instead")] - public MemberTypeService(IMemberService memberService) - : this(new PetaPocoUnitOfWorkProvider(), new RepositoryFactory(), memberService) - {} - - [Obsolete("Use the constructors that specify all dependencies instead")] - public MemberTypeService(RepositoryFactory repositoryFactory, IMemberService memberService) - : this(new PetaPocoUnitOfWorkProvider(), repositoryFactory, memberService) - { } - - [Obsolete("Use the constructors that specify all dependencies instead")] - public MemberTypeService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, IMemberService memberService) - : this(provider, repositoryFactory, LoggerResolver.Current.Logger, memberService) - { - } - public MemberTypeService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IMemberService memberService) : base(provider, repositoryFactory, logger) { diff --git a/src/Umbraco.Core/Services/PackagingService.cs b/src/Umbraco.Core/Services/PackagingService.cs index 2e22e81fe1..1e7b9558e8 100644 --- a/src/Umbraco.Core/Services/PackagingService.cs +++ b/src/Umbraco.Core/Services/PackagingService.cs @@ -17,6 +17,7 @@ using Umbraco.Core.Packaging.Models; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.Querying; using Umbraco.Core.Persistence.UnitOfWork; +using Umbraco.Core.Strings; namespace Umbraco.Core.Services { @@ -36,10 +37,12 @@ namespace Umbraco.Core.Services private readonly ILocalizationService _localizationService; private readonly RepositoryFactory _repositoryFactory; private readonly IDatabaseUnitOfWorkProvider _uowProvider; + private readonly IEnumerable _urlSegmentProviders; private Dictionary _importedContentTypes; private IPackageInstallation _packageInstallation; private readonly IUserService _userService; + //TODO: Perhaps this should just accept a ServiceContext instance? and not actually be part of the service context? public PackagingService( ILogger logger, @@ -52,7 +55,8 @@ namespace Umbraco.Core.Services ILocalizationService localizationService, IUserService userService, RepositoryFactory repositoryFactory, - IDatabaseUnitOfWorkProvider uowProvider) + IDatabaseUnitOfWorkProvider uowProvider, + IEnumerable urlSegmentProviders) { _logger = logger; _contentService = contentService; @@ -64,6 +68,7 @@ namespace Umbraco.Core.Services _localizationService = localizationService; _repositoryFactory = repositoryFactory; _uowProvider = uowProvider; + _urlSegmentProviders = urlSegmentProviders; _userService = userService; _importedContentTypes = new Dictionary(); } @@ -88,7 +93,7 @@ namespace Umbraco.Core.Services } var exporter = new EntityXmlSerializer(); - var xml = exporter.Serialize(_contentService, _dataTypeService, _userService, content, deep); + var xml = exporter.Serialize(_contentService, _dataTypeService, _userService, _urlSegmentProviders, content, deep); if (raiseEvents) ExportedContent.RaiseEvent(new ExportEventArgs(content, xml, false), this); @@ -1283,7 +1288,7 @@ namespace Umbraco.Core.Services } var exporter = new EntityXmlSerializer(); - var xml = exporter.Serialize(_mediaService, _dataTypeService, _userService, media, deep); + var xml = exporter.Serialize(_mediaService, _dataTypeService, _userService, _urlSegmentProviders, media, deep); if (raiseEvents) ExportedMedia.RaiseEvent(new ExportEventArgs(media, xml, false), this); diff --git a/src/Umbraco.Core/Services/ServiceContext.cs b/src/Umbraco.Core/Services/ServiceContext.cs index b635e33e9b..1618193c4e 100644 --- a/src/Umbraco.Core/Services/ServiceContext.cs +++ b/src/Umbraco.Core/Services/ServiceContext.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using log4net; using Umbraco.Core.Logging; using System.IO; @@ -6,6 +7,7 @@ using Umbraco.Core.IO; using Umbraco.Core.Persistence; using Umbraco.Core.Persistence.UnitOfWork; using Umbraco.Core.Publishing; +using Umbraco.Core.Strings; using umbraco.interfaces; namespace Umbraco.Core.Services @@ -65,6 +67,7 @@ namespace Umbraco.Core.Services /// /// /// + /// public ServiceContext( IContentService contentService = null, IMediaService mediaService = null, @@ -86,29 +89,31 @@ namespace Umbraco.Core.Services ILocalizedTextService localizedTextService = null, IAuditService auditService = null, IDomainService domainService = null, - ITaskService taskService = null) + ITaskService taskService = null, + IMacroService macroService = null) { - if (_auditService != null) _auditService = new Lazy(() => auditService); - if (_localizedTextService != null) _localizedTextService = new Lazy(() => localizedTextService); - if (_tagService != null) _tagService = new Lazy(() => tagService); - if (_contentService != null) _contentService = new Lazy(() => contentService); - if (_mediaService != null) _mediaService = new Lazy(() => mediaService); - if (_contentTypeService != null) _contentTypeService = new Lazy(() => contentTypeService); - if (_dataTypeService != null) _dataTypeService = new Lazy(() => dataTypeService); - if (_fileService != null) _fileService = new Lazy(() => fileService); - if (_localizationService != null) _localizationService = new Lazy(() => localizationService); - if (_packagingService != null) _packagingService = new Lazy(() => packagingService); - if (_entityService != null) _entityService = new Lazy(() => entityService); - if (_relationService != null) _relationService = new Lazy(() => relationService); - if (_sectionService != null) _sectionService = new Lazy(() => sectionService); - if (_memberGroupService != null) _memberGroupService = new Lazy(() => memberGroupService); - if (_memberTypeService != null) _memberTypeService = new Lazy(() => memberTypeService); - if (_treeService != null) _treeService = new Lazy(() => treeService); - if (_memberService != null) _memberService = new Lazy(() => memberService); - if (_userService != null) _userService = new Lazy(() => userService); - if (_notificationService != null) _notificationService = new Lazy(() => notificationService); - if (_domainService != null) _domainService = new Lazy(() => domainService); - if (_taskService != null) _taskService = new Lazy(() => taskService); + if (auditService != null) _auditService = new Lazy(() => auditService); + if (localizedTextService != null) _localizedTextService = new Lazy(() => localizedTextService); + if (tagService != null) _tagService = new Lazy(() => tagService); + if (contentService != null) _contentService = new Lazy(() => contentService); + if (mediaService != null) _mediaService = new Lazy(() => mediaService); + if (contentTypeService != null) _contentTypeService = new Lazy(() => contentTypeService); + if (dataTypeService != null) _dataTypeService = new Lazy(() => dataTypeService); + if (fileService != null) _fileService = new Lazy(() => fileService); + if (localizationService != null) _localizationService = new Lazy(() => localizationService); + if (packagingService != null) _packagingService = new Lazy(() => packagingService); + if (entityService != null) _entityService = new Lazy(() => entityService); + if (relationService != null) _relationService = new Lazy(() => relationService); + if (sectionService != null) _sectionService = new Lazy(() => sectionService); + if (memberGroupService != null) _memberGroupService = new Lazy(() => memberGroupService); + if (memberTypeService != null) _memberTypeService = new Lazy(() => memberTypeService); + if (treeService != null) _treeService = new Lazy(() => treeService); + if (memberService != null) _memberService = new Lazy(() => memberService); + if (userService != null) _userService = new Lazy(() => userService); + if (notificationService != null) _notificationService = new Lazy(() => notificationService); + if (domainService != null) _domainService = new Lazy(() => domainService); + if (taskService != null) _taskService = new Lazy(() => taskService); + if (macroService != null) _macroService = new Lazy(() => macroService); } internal ServiceContext( @@ -117,11 +122,13 @@ namespace Umbraco.Core.Services IUnitOfWorkProvider fileUnitOfWorkProvider, BasePublishingStrategy publishingStrategy, CacheHelper cache, - ILogger logger) + ILogger logger, + IEnumerable urlSegmentProviders) { BuildServiceCache(dbUnitOfWorkProvider, fileUnitOfWorkProvider, publishingStrategy, cache, repositoryFactory, - logger); + logger, + urlSegmentProviders); } /// @@ -133,7 +140,8 @@ namespace Umbraco.Core.Services BasePublishingStrategy publishingStrategy, CacheHelper cache, RepositoryFactory repositoryFactory, - ILogger logger) + ILogger logger, + IEnumerable urlSegmentProviders) { var provider = dbUnitOfWorkProvider; var fileProvider = fileUnitOfWorkProvider; @@ -165,10 +173,10 @@ namespace Umbraco.Core.Services _memberService = new Lazy(() => new MemberService(provider, repositoryFactory, logger, _memberGroupService.Value, _dataTypeService.Value)); if (_contentService == null) - _contentService = new Lazy(() => new ContentService(provider, repositoryFactory, logger, publishingStrategy, _dataTypeService.Value, _userService.Value)); + _contentService = new Lazy(() => new ContentService(provider, repositoryFactory, logger, publishingStrategy, _dataTypeService.Value, _userService.Value, urlSegmentProviders)); if (_mediaService == null) - _mediaService = new Lazy(() => new MediaService(provider, repositoryFactory, logger, _dataTypeService.Value, _userService.Value)); + _mediaService = new Lazy(() => new MediaService(provider, repositoryFactory, logger, _dataTypeService.Value, _userService.Value, urlSegmentProviders)); if (_contentTypeService == null) _contentTypeService = new Lazy(() => new ContentTypeService(provider, repositoryFactory, logger, _contentService.Value, _mediaService.Value)); @@ -183,7 +191,7 @@ namespace Umbraco.Core.Services _localizationService = new Lazy(() => new LocalizationService(provider, repositoryFactory, logger)); if (_packagingService == null) - _packagingService = new Lazy(() => new PackagingService(logger, _contentService.Value, _contentTypeService.Value, _mediaService.Value, _macroService.Value, _dataTypeService.Value, _fileService.Value, _localizationService.Value, _userService.Value, repositoryFactory, provider)); + _packagingService = new Lazy(() => new PackagingService(logger, _contentService.Value, _contentTypeService.Value, _mediaService.Value, _macroService.Value, _dataTypeService.Value, _fileService.Value, _localizationService.Value, _userService.Value, repositoryFactory, provider, urlSegmentProviders)); if (_entityService == null) _entityService = new Lazy(() => new EntityService( diff --git a/src/Umbraco.Core/Services/TagService.cs b/src/Umbraco.Core/Services/TagService.cs index 6054d29323..bb98764390 100644 --- a/src/Umbraco.Core/Services/TagService.cs +++ b/src/Umbraco.Core/Services/TagService.cs @@ -17,29 +17,6 @@ namespace Umbraco.Core.Services public class TagService : RepositoryService, ITagService { - [Obsolete("Use the constructors that specify all dependencies instead")] - public TagService() - : this(new RepositoryFactory()) - {} - - [Obsolete("Use the constructors that specify all dependencies instead")] - public TagService(RepositoryFactory repositoryFactory) - : this(new PetaPocoUnitOfWorkProvider(), repositoryFactory) - { - } - - [Obsolete("Use the constructors that specify all dependencies instead")] - public TagService(IDatabaseUnitOfWorkProvider provider) - : this(provider, new RepositoryFactory()) - { - } - - [Obsolete("Use the constructors that specify all dependencies instead")] - public TagService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory) - : this(provider, repositoryFactory, LoggerResolver.Current.Logger) - { - } - public TagService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger) : base(provider, repositoryFactory, logger) { diff --git a/src/Umbraco.Core/Services/UserService.cs b/src/Umbraco.Core/Services/UserService.cs index 1fce38e17a..acc72cd513 100644 --- a/src/Umbraco.Core/Services/UserService.cs +++ b/src/Umbraco.Core/Services/UserService.cs @@ -16,23 +16,6 @@ namespace Umbraco.Core.Services /// public class UserService : RepositoryService, IUserService { - - [Obsolete("Use the constructors that specify all dependencies instead")] - public UserService(RepositoryFactory repositoryFactory) - : this(new PetaPocoUnitOfWorkProvider(), repositoryFactory) - { } - - [Obsolete("Use the constructors that specify all dependencies instead")] - public UserService(IDatabaseUnitOfWorkProvider provider) - : this(provider, new RepositoryFactory()) - { } - - [Obsolete("Use the constructors that specify all dependencies instead")] - public UserService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory) - : base(provider, repositoryFactory, LoggerResolver.Current.Logger) - { - } - public UserService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger) : base(provider, repositoryFactory, logger) { diff --git a/src/Umbraco.Core/Standalone/ServiceContextManager.cs b/src/Umbraco.Core/Standalone/ServiceContextManager.cs index b036359dc6..084c92cc13 100644 --- a/src/Umbraco.Core/Standalone/ServiceContextManager.cs +++ b/src/Umbraco.Core/Standalone/ServiceContextManager.cs @@ -9,6 +9,7 @@ using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Core.Persistence.UnitOfWork; using Umbraco.Core.Publishing; using Umbraco.Core.Services; +using Umbraco.Core.Strings; namespace Umbraco.Core.Standalone { @@ -68,7 +69,8 @@ namespace Umbraco.Core.Standalone new FileUnitOfWorkProvider(), new PublishingStrategy(), cacheHelper, - new DebugDiagnosticsLogger()); + new DebugDiagnosticsLogger(), + UrlSegmentProviderResolver.Current.Providers); //initialize the DatabaseContext dbContext.Initialize(_providerName); diff --git a/src/Umbraco.Core/Strings/ContentBaseExtensions.cs b/src/Umbraco.Core/Strings/ContentBaseExtensions.cs index 1abb9f614c..8a8d69a7c7 100644 --- a/src/Umbraco.Core/Strings/ContentBaseExtensions.cs +++ b/src/Umbraco.Core/Strings/ContentBaseExtensions.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Globalization; using System.Linq; using Umbraco.Core.Models; @@ -10,30 +11,19 @@ namespace Umbraco.Core.Strings /// internal static class ContentBaseExtensions { - /// - /// Gets the url segment providers. - /// - /// This is so that unit tests that do not initialize the resolver do not - /// fail and fall back to defaults. When running the whole Umbraco, CoreBootManager - /// does initialise the resolver. - private static IEnumerable UrlSegmentProviders - { - get - { - return UrlSegmentProviderResolver.HasCurrent - ? UrlSegmentProviderResolver.Current.Providers - : new IUrlSegmentProvider[] { new DefaultUrlSegmentProvider() }; - } - } /// /// Gets the default url segment for a specified content. /// /// The content. + /// /// The url segment. - public static string GetUrlSegment(this IContentBase content) + public static string GetUrlSegment(this IContentBase content, IEnumerable urlSegmentProviders) { - var url = UrlSegmentProviders.Select(p => p.GetUrlSegment(content)).First(u => u != null); + if (content == null) throw new ArgumentNullException("content"); + if (urlSegmentProviders == null) throw new ArgumentNullException("urlSegmentProviders"); + + var url = urlSegmentProviders.Select(p => p.GetUrlSegment(content)).First(u => u != null); url = url ?? new DefaultUrlSegmentProvider().GetUrlSegment(content); // be safe return url; } @@ -43,10 +33,15 @@ namespace Umbraco.Core.Strings /// /// The content. /// The culture. + /// /// The url segment. - public static string GetUrlSegment(this IContentBase content, CultureInfo culture) + public static string GetUrlSegment(this IContentBase content, CultureInfo culture, IEnumerable urlSegmentProviders) { - var url = UrlSegmentProviders.Select(p => p.GetUrlSegment(content, culture)).First(u => u != null); + if (content == null) throw new ArgumentNullException("content"); + if (culture == null) throw new ArgumentNullException("culture"); + if (urlSegmentProviders == null) throw new ArgumentNullException("urlSegmentProviders"); + + var url = urlSegmentProviders.Select(p => p.GetUrlSegment(content, culture)).First(u => u != null); url = url ?? new DefaultUrlSegmentProvider().GetUrlSegment(content, culture); // be safe return url; } diff --git a/src/Umbraco.Tests/Models/ContentXmlTest.cs b/src/Umbraco.Tests/Models/ContentXmlTest.cs index f1a42c20b6..f3b8ab520e 100644 --- a/src/Umbraco.Tests/Models/ContentXmlTest.cs +++ b/src/Umbraco.Tests/Models/ContentXmlTest.cs @@ -21,10 +21,6 @@ namespace Umbraco.Tests.Models protected override void FreezeResolution() { - UrlSegmentProviderResolver.Current = new UrlSegmentProviderResolver( - new ActivatorServiceProvider(), - Logger, - typeof(DefaultUrlSegmentProvider)); base.FreezeResolution(); } @@ -44,7 +40,7 @@ namespace Umbraco.Tests.Models ServiceContext.ContentService.Save(content, 0); var nodeName = content.ContentType.Alias.ToSafeAliasWithForcingCheck(); - var urlName = content.GetUrlSegment(); + var urlName = content.GetUrlSegment(new[]{new DefaultUrlSegmentProvider() }); // Act XElement element = content.ToXml(); diff --git a/src/Umbraco.Tests/Models/MediaXmlTest.cs b/src/Umbraco.Tests/Models/MediaXmlTest.cs index ff7e3cb08f..b95b04061f 100644 --- a/src/Umbraco.Tests/Models/MediaXmlTest.cs +++ b/src/Umbraco.Tests/Models/MediaXmlTest.cs @@ -21,10 +21,6 @@ namespace Umbraco.Tests.Models protected override void FreezeResolution() { - UrlSegmentProviderResolver.Current = new UrlSegmentProviderResolver( - new ActivatorServiceProvider(), - Logger, - typeof(DefaultUrlSegmentProvider)); base.FreezeResolution(); } @@ -45,7 +41,7 @@ namespace Umbraco.Tests.Models ServiceContext.MediaService.Save(media, 0); var nodeName = media.ContentType.Alias.ToSafeAliasWithForcingCheck(); - var urlName = media.GetUrlSegment(); + var urlName = media.GetUrlSegment(new[] { new DefaultUrlSegmentProvider() }); // Act XElement element = media.ToXml(); diff --git a/src/Umbraco.Tests/Mvc/UmbracoViewPageTests.cs b/src/Umbraco.Tests/Mvc/UmbracoViewPageTests.cs index 9c76cbefe0..eeb0da3f18 100644 --- a/src/Umbraco.Tests/Mvc/UmbracoViewPageTests.cs +++ b/src/Umbraco.Tests/Mvc/UmbracoViewPageTests.cs @@ -374,45 +374,9 @@ namespace Umbraco.Tests.Mvc #region Test helpers - ServiceContext GetServiceContext(IUmbracoSettingsSection umbracoSettings, ILogger logger) + ServiceContext GetServiceContext() { - var svcCtx = new ServiceContext( - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new PackagingService( - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new RepositoryFactory(CacheHelper.CreateDisabledCacheHelper(), logger, Mock.Of(), umbracoSettings), - new Mock().Object), - new Mock().Object, - new RelationService( - new Mock().Object, - new RepositoryFactory(CacheHelper.CreateDisabledCacheHelper(), logger, Mock.Of(), umbracoSettings), - logger, - new Mock().Object), - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - Mock.Of(), - Mock.Of(), - Mock.Of()); - return svcCtx; + return MockHelper.GetMockedServiceContext(); } ViewContext GetViewContext() @@ -423,7 +387,10 @@ namespace Umbraco.Tests.Mvc logger, settings, "/dang", 0); - var urlProvider = new UrlProvider(umbracoContext, settings.WebRouting, new IUrlProvider[] { new DefaultUrlProvider() }); + var urlProvider = new UrlProvider(umbracoContext, settings.WebRouting, new IUrlProvider[] + { + new DefaultUrlProvider(settings.RequestHandler) + }); var routingContext = new RoutingContext( umbracoContext, Enumerable.Empty(), @@ -456,7 +423,7 @@ namespace Umbraco.Tests.Mvc //PublishedContentCache.UnitTesting = true; // ApplicationContext.Current = new ApplicationContext(false) { IsReady = true }; - var svcCtx = GetServiceContext(umbracoSettings, logger); + var svcCtx = GetServiceContext(); var appCtx = new ApplicationContext( new DatabaseContext(Mock.Of(), logger, Mock.Of(), "test"), diff --git a/src/Umbraco.Tests/Persistence/BaseTableByTableTest.cs b/src/Umbraco.Tests/Persistence/BaseTableByTableTest.cs index c21c1ae152..1cdf11eb99 100644 --- a/src/Umbraco.Tests/Persistence/BaseTableByTableTest.cs +++ b/src/Umbraco.Tests/Persistence/BaseTableByTableTest.cs @@ -15,6 +15,7 @@ using Umbraco.Core.Persistence.UnitOfWork; using Umbraco.Core.Profiling; using Umbraco.Core.Publishing; using Umbraco.Core.Services; +using Umbraco.Core.Strings; using Umbraco.Tests.TestHelpers; using GlobalSettings = Umbraco.Core.Configuration.GlobalSettings; @@ -59,7 +60,7 @@ namespace Umbraco.Tests.Persistence //assign the db context dbContext, //assign the service context - new ServiceContext(repositoryFactory, new PetaPocoUnitOfWorkProvider(_logger), new FileUnitOfWorkProvider(), new PublishingStrategy(), cacheHelper, _logger), + new ServiceContext(repositoryFactory, new PetaPocoUnitOfWorkProvider(_logger), new FileUnitOfWorkProvider(), new PublishingStrategy(), cacheHelper, _logger, new[] { new DefaultUrlSegmentProvider() }), cacheHelper, new ProfilingLogger(new Logger(new FileInfo(TestHelper.MapPathForTest("~/unit-test-log4net.config"))), Mock.Of())) { diff --git a/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs index d130cf72b5..bee804d800 100644 --- a/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs +++ b/src/Umbraco.Tests/Persistence/Repositories/StylesheetRepositoryTest.cs @@ -223,6 +223,8 @@ p{font-size:2em;}")); [TearDown] public override void TearDown() { + base.TearDown(); + //Delete all files var files = _fileSystem.GetFiles("", "*.css"); foreach (var file in files) diff --git a/src/Umbraco.Tests/Routing/UrlRoutingTestBase.cs b/src/Umbraco.Tests/Routing/UrlRoutingTestBase.cs index 089f78ac3e..295bb695e5 100644 --- a/src/Umbraco.Tests/Routing/UrlRoutingTestBase.cs +++ b/src/Umbraco.Tests/Routing/UrlRoutingTestBase.cs @@ -34,7 +34,7 @@ namespace Umbraco.Tests.Routing protected ServiceContext GetServiceContext(IUmbracoSettingsSection umbracoSettings, ILogger logger) { //get the mocked service context to get the mocked domain service - var svcCtx = MockHelper.GetMockedServiceContext(umbracoSettings, logger); + var svcCtx = MockHelper.GetMockedServiceContext(); var domainService = Mock.Get(svcCtx.DomainService); //setup mock domain service domainService.Setup(service => service.GetAll(It.IsAny())) diff --git a/src/Umbraco.Tests/Services/Importing/CheckboxList-Content-Package-LegacyIds.xml b/src/Umbraco.Tests/Services/Importing/CheckboxList-Content-Package-LegacyIds.xml deleted file mode 100644 index 8a8380cf65..0000000000 --- a/src/Umbraco.Tests/Services/Importing/CheckboxList-Content-Package-LegacyIds.xml +++ /dev/null @@ -1,76 +0,0 @@ - - - - - - CheckboxListTest - 1 - MIT license - 1 - - 3 - 0 - 0 - - - - 1 - 1 - - - - - - - - - - - - - - NewType - NewType - .sprTreeFolder - folder.png - - - True - - - - NewType - - - - - testList - testList - b4471851-82b6-4c75-afa4-39fa9c6a75e9 - 8dacee1a-1bbd-46c0-b07f-8ffd49fcca7c - - - False - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Umbraco.Tests/Services/Importing/ImportResources.Designer.cs b/src/Umbraco.Tests/Services/Importing/ImportResources.Designer.cs index bcc287e2ae..2f36116373 100644 --- a/src/Umbraco.Tests/Services/Importing/ImportResources.Designer.cs +++ b/src/Umbraco.Tests/Services/Importing/ImportResources.Designer.cs @@ -1,7 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. -// Runtime Version:4.0.30319.34209 +// Runtime Version:4.0.30319.0 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -88,34 +88,6 @@ namespace Umbraco.Tests.Services.Importing { } } - /// - /// Looks up a localized string similar to <?xml version="1.0" encoding="UTF-8" standalone="no"?> - ///<umbPackage> - /// <files /> - /// <info> - /// <package> - /// <name>CheckboxListTest</name> - /// <version>1</version> - /// <license url="http://www.opensource.org/licenses/mit-license.php">MIT license</license> - /// <url>1</url> - /// <requirements> - /// <major>3</major> - /// <minor>0</minor> - /// <patch>0</patch> - /// </requirements> - /// </package> - /// <author> - /// <name>1</name> - /// <website>1</website> - /// </author> - /// <r [rest of string was truncated]";. - /// - internal static string CheckboxList_Content_Package_LegacyIds { - get { - return ResourceManager.GetString("CheckboxList_Content_Package_LegacyIds", resourceCulture); - } - } - /// /// Looks up a localized string similar to <?xml version="1.0" encoding="UTF-8" standalone="no"?> ///<umbPackage> diff --git a/src/Umbraco.Tests/Services/Importing/ImportResources.resx b/src/Umbraco.Tests/Services/Importing/ImportResources.resx index f6a447531a..fb9b2869df 100644 --- a/src/Umbraco.Tests/Services/Importing/ImportResources.resx +++ b/src/Umbraco.Tests/Services/Importing/ImportResources.resx @@ -142,9 +142,6 @@ checkboxlist-content-package.xml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 - - checkboxlist-content-package-legacyids.xml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 - dictionary-package.xml;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;utf-8 diff --git a/src/Umbraco.Tests/Services/Importing/PackageImportTests.cs b/src/Umbraco.Tests/Services/Importing/PackageImportTests.cs index 215f24e375..6846907f35 100644 --- a/src/Umbraco.Tests/Services/Importing/PackageImportTests.cs +++ b/src/Umbraco.Tests/Services/Importing/PackageImportTests.cs @@ -268,11 +268,7 @@ namespace Umbraco.Tests.Services.Importing AssertCheckBoxListTests(ImportResources.CheckboxList_Content_Package); } - [Test] - public void PackagingService_Can_Import_CheckboxList_Content_Package_Xml_With_Legacy_Property_Editor_Ids() - { - AssertCheckBoxListTests(ImportResources.CheckboxList_Content_Package_LegacyIds); - } + private void AssertCheckBoxListTests(string strXml) { diff --git a/src/Umbraco.Tests/Services/ThreadSafetyServiceTest.cs b/src/Umbraco.Tests/Services/ThreadSafetyServiceTest.cs index f67289e644..10839ad754 100644 --- a/src/Umbraco.Tests/Services/ThreadSafetyServiceTest.cs +++ b/src/Umbraco.Tests/Services/ThreadSafetyServiceTest.cs @@ -13,6 +13,7 @@ using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Core.Persistence.UnitOfWork; using Umbraco.Core.Publishing; using Umbraco.Core.Services; +using Umbraco.Core.Strings; using Umbraco.Tests.TestHelpers; using Umbraco.Tests.TestHelpers.Entities; @@ -52,7 +53,8 @@ namespace Umbraco.Tests.Services new FileUnitOfWorkProvider(), new PublishingStrategy(), cacheHelper, - Logger); + Logger, + new[] { new DefaultUrlSegmentProvider() }); CreateTestData(); } diff --git a/src/Umbraco.Tests/Strings/DefaultShortStringHelperTests.cs b/src/Umbraco.Tests/Strings/DefaultShortStringHelperTests.cs index fba1775f50..52bb6be16d 100644 --- a/src/Umbraco.Tests/Strings/DefaultShortStringHelperTests.cs +++ b/src/Umbraco.Tests/Strings/DefaultShortStringHelperTests.cs @@ -127,7 +127,6 @@ namespace Umbraco.Tests.Strings var contentMock = Mock.Get(settings.RequestHandler); contentMock.Setup(x => x.CharCollection).Returns(Enumerable.Empty()); contentMock.Setup(x => x.ConvertUrlsToAscii).Returns(false); - SettingsForTests.ConfigureSettings(settings); const string input = "ÆØÅ and æøå and 中文测试 and אודות האתר and größer БбДдЖж page"; @@ -413,9 +412,8 @@ namespace Umbraco.Tests.Strings var contentMock = Mock.Get(settings.RequestHandler); contentMock.Setup(x => x.CharCollection).Returns(Enumerable.Empty()); contentMock.Setup(x => x.ConvertUrlsToAscii).Returns(false); - SettingsForTests.ConfigureSettings(settings); - var helper = new DefaultShortStringHelper(SettingsForTests.GetDefault()).WithDefaultConfig(); + var helper = new DefaultShortStringHelper(settings).WithDefaultConfig(); const string input = "0123 中文测试 中文测试 léger ZÔRG (2) a?? *x"; diff --git a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs index 1e12bbe810..567e09ea11 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseDatabaseFactoryTest.cs @@ -26,6 +26,7 @@ using Umbraco.Core.Persistence.UnitOfWork; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Publishing; using Umbraco.Core.Services; +using Umbraco.Core.Strings; using Umbraco.Web; using Umbraco.Web.PublishedCache; using Umbraco.Web.PublishedCache.XmlPublishedCache; @@ -81,7 +82,7 @@ namespace Umbraco.Tests.TestHelpers //assign the db context new DatabaseContext(dbFactory, Logger, SqlSyntax, "System.Data.SqlServerCe.4.0"), //assign the service context - new ServiceContext(repositoryFactory, new PetaPocoUnitOfWorkProvider(dbFactory), new FileUnitOfWorkProvider(), new PublishingStrategy(), cacheHelper, Logger), + new ServiceContext(repositoryFactory, new PetaPocoUnitOfWorkProvider(dbFactory), new FileUnitOfWorkProvider(), new PublishingStrategy(), cacheHelper, Logger, new[] { new DefaultUrlSegmentProvider() }), cacheHelper, ProfilingLogger) { diff --git a/src/Umbraco.Tests/TestHelpers/BaseDatabaseTest.cs b/src/Umbraco.Tests/TestHelpers/BaseDatabaseTest.cs index eedd100a0d..2167190167 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseDatabaseTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseDatabaseTest.cs @@ -16,6 +16,7 @@ using Umbraco.Core.Persistence.UnitOfWork; using Umbraco.Core.Profiling; using Umbraco.Core.Publishing; using Umbraco.Core.Services; +using Umbraco.Core.Strings; using GlobalSettings = Umbraco.Core.Configuration.GlobalSettings; namespace Umbraco.Tests.TestHelpers @@ -72,7 +73,7 @@ namespace Umbraco.Tests.TestHelpers //assign the db context new DatabaseContext(dbFactory, logger, SqlSyntaxProviders.CreateDefault(logger)), //assign the service context - new ServiceContext(repositoryFactory, new PetaPocoUnitOfWorkProvider(dbFactory), new FileUnitOfWorkProvider(), new PublishingStrategy(), cacheHelper, logger), + new ServiceContext(repositoryFactory, new PetaPocoUnitOfWorkProvider(dbFactory), new FileUnitOfWorkProvider(), new PublishingStrategy(), cacheHelper, logger, new[] { new DefaultUrlSegmentProvider() }), cacheHelper, new ProfilingLogger(logger, Mock.Of())) { diff --git a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs index 22c05c6694..d347abec0e 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseUmbracoApplicationTest.cs @@ -4,10 +4,12 @@ using System.Collections.Generic; using System.IO; using System.Reflection; using AutoMapper; +using Moq; using NUnit.Framework; using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Configuration.UmbracoSettings; +using Umbraco.Core.IO; using Umbraco.Core.LightInject; using Umbraco.Core.Logging; using Umbraco.Core.Models.Mapping; @@ -20,6 +22,7 @@ using Umbraco.Core.Profiling; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Publishing; using Umbraco.Core.Services; +using Umbraco.Core.Strings; using Umbraco.Web; using Umbraco.Web.Models.Mapping; using umbraco.BusinessLogic; @@ -71,6 +74,7 @@ namespace Umbraco.Tests.TestHelpers Container.Register(factory => settings.Content, new PerContainerLifetime()); Container.Register(factory => CacheHelper.RuntimeCache); Container.Register(); + Container.Register(factory => new MediaFileSystem(Mock.Of())); FreezeResolution(); @@ -177,7 +181,7 @@ namespace Umbraco.Tests.TestHelpers new DatabaseContext(new DefaultDatabaseFactory(Core.Configuration.GlobalSettings.UmbracoConnectionName, Logger), Logger, sqlSyntax, "System.Data.SqlServerCe.4.0"), //assign the service context - new ServiceContext(repoFactory, new PetaPocoUnitOfWorkProvider(Logger), new FileUnitOfWorkProvider(), new PublishingStrategy(), CacheHelper, Logger), + new ServiceContext(repoFactory, new PetaPocoUnitOfWorkProvider(Logger), new FileUnitOfWorkProvider(), new PublishingStrategy(), CacheHelper, Logger, new[] { new DefaultUrlSegmentProvider() }), CacheHelper, ProfilingLogger) { @@ -204,9 +208,6 @@ namespace Umbraco.Tests.TestHelpers Assembly.Load("businesslogic"), Assembly.Load("cms"), Assembly.Load("controls"), - Assembly.Load("umbraco.MacroEngines"), - Assembly.Load("umbraco.providers"), - Assembly.Load("Umbraco.Web.UI"), } }; } diff --git a/src/Umbraco.Tests/TestHelpers/BaseWebTest.cs b/src/Umbraco.Tests/TestHelpers/BaseWebTest.cs index f76e5bbea8..d3e5c070bc 100644 --- a/src/Umbraco.Tests/TestHelpers/BaseWebTest.cs +++ b/src/Umbraco.Tests/TestHelpers/BaseWebTest.cs @@ -83,7 +83,7 @@ namespace Umbraco.Tests.TestHelpers /// protected override void FreezeResolution() { - Container.Register(factory => new MediaFileSystem(Mock.Of())); + base.FreezeResolution(); } diff --git a/src/Umbraco.Tests/TestHelpers/MockHelper.cs b/src/Umbraco.Tests/TestHelpers/MockHelper.cs index ae7245b855..f81c7439d7 100644 --- a/src/Umbraco.Tests/TestHelpers/MockHelper.cs +++ b/src/Umbraco.Tests/TestHelpers/MockHelper.cs @@ -11,13 +11,8 @@ namespace Umbraco.Tests.TestHelpers { public static class MockHelper { - public static ServiceContext GetMockedServiceContext(IUmbracoSettingsSection settings = null, ILogger logger = null, CacheHelper cacheHelper = null, ISqlSyntaxProvider sqlSyntax = null) + public static ServiceContext GetMockedServiceContext() { - if (settings == null) settings = SettingsForTests.GetDefault(); - if (logger == null) logger = Mock.Of(); - if (cacheHelper == null) cacheHelper = CacheHelper.CreateDisabledCacheHelper(); - if (sqlSyntax == null) sqlSyntax = Mock.Of(); - return new ServiceContext( new Mock().Object, new Mock().Object, @@ -25,24 +20,9 @@ namespace Umbraco.Tests.TestHelpers new Mock().Object, new Mock().Object, new Mock().Object, - new PackagingService( - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new Mock().Object, - new RepositoryFactory(cacheHelper, logger, sqlSyntax, settings), - new Mock().Object), + new Mock().Object, new Mock().Object, - new RelationService( - new Mock().Object, - new RepositoryFactory(cacheHelper, logger, sqlSyntax, settings), - logger, - new Mock().Object), + new Mock().Object, new Mock().Object, new Mock().Object, new Mock().Object, @@ -53,7 +33,9 @@ namespace Umbraco.Tests.TestHelpers new Mock().Object, new Mock().Object, new Mock().Object, - new Mock().Object); + new Mock().Object, + new Mock().Object, + new Mock().Object); } } } \ No newline at end of file diff --git a/src/Umbraco.Tests/Umbraco.Tests.csproj b/src/Umbraco.Tests/Umbraco.Tests.csproj index 035ad0123a..3f28a44a1d 100644 --- a/src/Umbraco.Tests/Umbraco.Tests.csproj +++ b/src/Umbraco.Tests/Umbraco.Tests.csproj @@ -646,9 +646,6 @@ - - Designer - Designer diff --git a/src/Umbraco.Tests/UmbracoExamine/IndexInitializer.cs b/src/Umbraco.Tests/UmbracoExamine/IndexInitializer.cs index 6c81bdb3fc..aa59ead333 100644 --- a/src/Umbraco.Tests/UmbracoExamine/IndexInitializer.cs +++ b/src/Umbraco.Tests/UmbracoExamine/IndexInitializer.cs @@ -12,6 +12,7 @@ using Umbraco.Core.Models; using Umbraco.Core.Models.Membership; using Umbraco.Core.Persistence.DatabaseModelDefinitions; using Umbraco.Core.Services; +using Umbraco.Core.Strings; using UmbracoExamine; using UmbracoExamine.Config; using UmbracoExamine.DataServices; @@ -104,6 +105,7 @@ namespace Umbraco.Tests.UmbracoExamine mediaService, dataTypeService, userService, + new[] { new DefaultUrlSegmentProvider() }, analyzer, false); diff --git a/src/Umbraco.Web/Standalone/ServiceContextManager.cs b/src/Umbraco.Web/Standalone/ServiceContextManager.cs index 32c0867429..d4336c7688 100644 --- a/src/Umbraco.Web/Standalone/ServiceContextManager.cs +++ b/src/Umbraco.Web/Standalone/ServiceContextManager.cs @@ -10,6 +10,7 @@ using Umbraco.Core.Persistence.SqlSyntax; using Umbraco.Core.Persistence.UnitOfWork; using Umbraco.Core.Publishing; using Umbraco.Core.Services; +using Umbraco.Core.Strings; namespace Umbraco.Web.Standalone { @@ -62,7 +63,8 @@ namespace Umbraco.Web.Standalone new FileUnitOfWorkProvider(), new PublishingStrategy(), cacheHelper, - new DebugDiagnosticsLogger()); + new DebugDiagnosticsLogger(), + UrlSegmentProviderResolver.Current.Providers); //initialize the DatabaseContext dbContext.Initialize(_providerName); diff --git a/src/Umbraco.Web/WebBootManager.cs b/src/Umbraco.Web/WebBootManager.cs index c7286c439d..5edea2658f 100644 --- a/src/Umbraco.Web/WebBootManager.cs +++ b/src/Umbraco.Web/WebBootManager.cs @@ -305,6 +305,8 @@ namespace Umbraco.Web //register other services container.Register(); container.Register(); + //no need to declare as per request, currently we manage it's lifetime as the singleton + container.Register(factory => UmbracoContext.Current); } /// diff --git a/src/Umbraco.Web/umbraco.presentation/library.cs b/src/Umbraco.Web/umbraco.presentation/library.cs index dbabffe4c7..bf6e2dc60d 100644 --- a/src/Umbraco.Web/umbraco.presentation/library.cs +++ b/src/Umbraco.Web/umbraco.presentation/library.cs @@ -19,6 +19,7 @@ using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Logging; using Umbraco.Core.Models; using Umbraco.Core.Services; +using Umbraco.Core.Strings; using Umbraco.Web; using Umbraco.Web.Cache; using Umbraco.Web.Templates; @@ -481,7 +482,8 @@ namespace umbraco var serialized = serializer.Serialize( ApplicationContext.Current.Services.MediaService, ApplicationContext.Current.Services.DataTypeService, - ApplicationContext.Current.Services.UserService, + ApplicationContext.Current.Services.UserService, + UrlSegmentProviderResolver.Current.Providers, media, deep); return serialized; diff --git a/src/UmbracoExamine/UmbracoContentIndexer.cs b/src/UmbracoExamine/UmbracoContentIndexer.cs index 26ae4a9f5f..c44e79cabe 100644 --- a/src/UmbracoExamine/UmbracoContentIndexer.cs +++ b/src/UmbracoExamine/UmbracoContentIndexer.cs @@ -18,6 +18,7 @@ using umbraco.cms.businesslogic; using Umbraco.Core.Models; using Umbraco.Core.Persistence.DatabaseModelDefinitions; using Umbraco.Core.Services; +using Umbraco.Core.Strings; using UmbracoExamine.DataServices; using Examine.LuceneEngine; using Examine.LuceneEngine.Config; @@ -37,10 +38,11 @@ namespace UmbracoExamine /// public class UmbracoContentIndexer : BaseUmbracoIndexer { - private readonly IContentService _contentService; - private readonly IMediaService _mediaService; - private readonly IDataTypeService _dataTypeService; - private readonly IUserService _userService; + protected IContentService ContentService { get; private set; } + protected IMediaService MediaService { get; private set; } + protected IDataTypeService DataTypeService { get; private set; } + protected IUserService UserService { get; private set; } + private readonly IEnumerable _urlSegmentProviders; #region Constructors @@ -50,47 +52,13 @@ namespace UmbracoExamine public UmbracoContentIndexer() : base() { - _contentService = ApplicationContext.Current.Services.ContentService; - _mediaService = ApplicationContext.Current.Services.MediaService; - _dataTypeService = ApplicationContext.Current.Services.DataTypeService; - _userService = ApplicationContext.Current.Services.UserService; + ContentService = ApplicationContext.Current.Services.ContentService; + MediaService = ApplicationContext.Current.Services.MediaService; + DataTypeService = ApplicationContext.Current.Services.DataTypeService; + UserService = ApplicationContext.Current.Services.UserService; + _urlSegmentProviders = UrlSegmentProviderResolver.Current.Providers; } - /// - /// Constructor to allow for creating an indexer at runtime - /// - /// - /// - /// - /// - /// - [Obsolete("Use the overload that specifies the Umbraco services")] - public UmbracoContentIndexer(IIndexCriteria indexerData, DirectoryInfo indexPath, IDataService dataService, Analyzer analyzer, bool async) - : base(indexerData, indexPath, dataService, analyzer, async) - { - _contentService = ApplicationContext.Current.Services.ContentService; - _mediaService = ApplicationContext.Current.Services.MediaService; - _dataTypeService = ApplicationContext.Current.Services.DataTypeService; - _userService = ApplicationContext.Current.Services.UserService; - } - - /// - /// Constructor to allow for creating an indexer at runtime - /// - /// - /// - /// - /// - /// - [Obsolete("Use the overload that specifies the Umbraco services")] - public UmbracoContentIndexer(IIndexCriteria indexerData, Lucene.Net.Store.Directory luceneDirectory, IDataService dataService, Analyzer analyzer, bool async) - : base(indexerData, luceneDirectory, dataService, analyzer, async) - { - _contentService = ApplicationContext.Current.Services.ContentService; - _mediaService = ApplicationContext.Current.Services.MediaService; - _dataTypeService = ApplicationContext.Current.Services.DataTypeService; - _userService = ApplicationContext.Current.Services.UserService; - } /// /// Constructor to allow for creating an indexer at runtime @@ -102,6 +70,7 @@ namespace UmbracoExamine /// /// /// + /// /// /// public UmbracoContentIndexer(IIndexCriteria indexerData, Lucene.Net.Store.Directory luceneDirectory, IDataService dataService, @@ -109,13 +78,16 @@ namespace UmbracoExamine IMediaService mediaService, IDataTypeService dataTypeService, IUserService userService, - Analyzer analyzer, bool async) + IEnumerable urlSegmentProviders, + Analyzer analyzer, + bool async) : base(indexerData, luceneDirectory, dataService, analyzer, async) { - _contentService = contentService; - _mediaService = mediaService; - _dataTypeService = dataTypeService; - _userService = userService; + ContentService = contentService; + MediaService = mediaService; + DataTypeService = dataTypeService; + UserService = userService; + _urlSegmentProviders = urlSegmentProviders; } #endregion @@ -371,7 +343,7 @@ namespace UmbracoExamine do { int total; - var descendants = _contentService.GetPagedDescendants(contentParentId, pageIndex, pageSize, out total); + var descendants = ContentService.GetPagedDescendants(contentParentId, pageIndex, pageSize, out total); //if specific types are declared we need to post filter them //TODO: Update the service layer to join the cmsContentType table so we can query by content type too @@ -402,7 +374,7 @@ namespace UmbracoExamine do { int total; - var descendants = _mediaService.GetPagedDescendants(mediaParentId, pageIndex, pageSize, out total); + var descendants = MediaService.GetPagedDescendants(mediaParentId, pageIndex, pageSize, out total); //if specific types are declared we need to post filter them //TODO: Update the service layer to join the cmsContentType table so we can query by content type too @@ -429,9 +401,10 @@ namespace UmbracoExamine foreach (var m in media) { var xml = serializer.Serialize( - _mediaService, - _dataTypeService, - _userService, + MediaService, + DataTypeService, + UserService, + _urlSegmentProviders, m); //add a custom 'icon' attribute @@ -451,9 +424,10 @@ namespace UmbracoExamine foreach (var c in content) { var xml = serializer.Serialize( - _contentService, - _dataTypeService, - _userService, + ContentService, + DataTypeService, + UserService, + _urlSegmentProviders, c); //add a custom 'icon' attribute diff --git a/src/UmbracoExamine/UmbracoMemberIndexer.cs b/src/UmbracoExamine/UmbracoMemberIndexer.cs index cdb9c4ffde..9d4173ea13 100644 --- a/src/UmbracoExamine/UmbracoMemberIndexer.cs +++ b/src/UmbracoExamine/UmbracoMemberIndexer.cs @@ -6,71 +6,69 @@ using Umbraco.Core; using Umbraco.Core.Models; using Umbraco.Core.Persistence.DatabaseModelDefinitions; using Umbraco.Core.Services; +using Umbraco.Core.Strings; using UmbracoExamine.Config; using System.Collections.Generic; using Examine; using System.IO; using UmbracoExamine.DataServices; using Lucene.Net.Analysis; +using Directory = Lucene.Net.Store.Directory; +using IContentService = Umbraco.Core.Services.IContentService; +using IMediaService = Umbraco.Core.Services.IMediaService; namespace UmbracoExamine { - /// + /// /// /// public class UmbracoMemberIndexer : UmbracoContentIndexer { private readonly IMemberService _memberService; - private readonly IDataTypeService _dataTypeService; - /// - /// Default constructor - /// - public UmbracoMemberIndexer() : base() - { - _dataTypeService = ApplicationContext.Current.Services.DataTypeService; + /// + /// Default constructor + /// + public UmbracoMemberIndexer() + : base() + { _memberService = ApplicationContext.Current.Services.MemberService; - } - - /// - /// Constructor to allow for creating an indexer at runtime - /// - /// - /// - /// - /// - [Obsolete("Use the overload that specifies the Umbraco services")] - public UmbracoMemberIndexer(IIndexCriteria indexerData, DirectoryInfo indexPath, IDataService dataService, Analyzer analyzer, bool async) - : base(indexerData, indexPath, dataService, analyzer, async) - { - _dataTypeService = ApplicationContext.Current.Services.DataTypeService; - _memberService = ApplicationContext.Current.Services.MemberService; - } + } /// /// Constructor to allow for creating an indexer at runtime /// /// - /// - /// - /// + /// /// + /// + /// + /// + /// + /// + /// /// /// - public UmbracoMemberIndexer(IIndexCriteria indexerData, DirectoryInfo indexPath, IDataService dataService, - IDataTypeService dataTypeService, + public UmbracoMemberIndexer( + IIndexCriteria indexerData, + Directory luceneDirectory, IMemberService memberService, - Analyzer analyzer, bool async) - : base(indexerData, indexPath, dataService, analyzer, async) - { - _dataTypeService = dataTypeService; + IDataService dataService, + IContentService contentService, + IMediaService mediaService, + IDataTypeService dataTypeService, + IUserService userService, + IEnumerable urlSegmentProviders, + Analyzer analyzer, + bool async) : + base(indexerData, luceneDirectory, dataService, contentService, mediaService, dataTypeService, userService, urlSegmentProviders, analyzer, async) + { + if (memberService == null) throw new ArgumentNullException("memberService"); _memberService = memberService; - } + } - - - /// + /// /// Ensures that the'_searchEmail' is added to the user fields so that it is indexed - without having to modify the config /// /// @@ -78,7 +76,7 @@ namespace UmbracoExamine protected override IIndexCriteria GetIndexerData(IndexSet indexSet) { if (CanInitialize()) - { + { var searchableEmail = indexSet.IndexUserFields["_searchEmail"]; if (searchableEmail == null) { @@ -93,7 +91,7 @@ namespace UmbracoExamine return base.GetIndexerData(indexSet); } - /// + /// /// The supported types for this indexer /// protected override IEnumerable SupportedTypes @@ -104,12 +102,12 @@ namespace UmbracoExamine } } - /// - /// Reindex all members - /// - /// - protected override void PerformIndexAll(string type) - { + /// + /// Reindex all members + /// + /// + protected override void PerformIndexAll(string type) + { //This only supports members if (SupportedTypes.Contains(type) == false) return; @@ -119,11 +117,11 @@ namespace UmbracoExamine const int pageSize = 5000; var pageIndex = 0; - if (IndexerData.IncludeNodeTypes.Any()) - { + if (IndexerData.IncludeNodeTypes.Any()) + { //if there are specific node types then just index those foreach (var nodeType in IndexerData.IncludeNodeTypes) - { + { do { int total; @@ -131,10 +129,10 @@ namespace UmbracoExamine AddNodesToIndex(GetSerializedMembers(members), type); pageIndex++; } while (members.Length == pageSize); - } - } - else - { + } + } + else + { //no node types specified, do all members do { @@ -143,30 +141,30 @@ namespace UmbracoExamine AddNodesToIndex(GetSerializedMembers(members), type); pageIndex++; } while (members.Length == pageSize); - } - } + } + } - private IEnumerable GetSerializedMembers(IEnumerable members) + private IEnumerable GetSerializedMembers(IEnumerable members) { var serializer = new EntityXmlSerializer(); foreach (var member in members) { - yield return serializer.Serialize(_dataTypeService, member); + yield return serializer.Serialize(DataTypeService, member); } - } + } + + protected override XDocument GetXDocument(string xPath, string type) + { + throw new NotSupportedException(); + } - protected override XDocument GetXDocument(string xPath, string type) - { - throw new NotSupportedException(); - } - protected override Dictionary GetSpecialFieldsToIndex(Dictionary allValuesForIndexing) { var fields = base.GetSpecialFieldsToIndex(allValuesForIndexing); //adds the special path property to the index fields.Add("__key", allValuesForIndexing["__key"]); - + return fields; }