From de34379ddff67d5f00affbe11d4c2f0dd8c37a10 Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Wed, 20 Aug 2014 14:08:45 +0200 Subject: [PATCH] Updating PR after feedback from @sitereactor --- src/Umbraco.Core/Services/FileService.cs | 11 ++++++----- src/Umbraco.Core/Services/ServiceContext.cs | 2 +- src/Umbraco.Web/WebServices/SaveFileController.cs | 2 +- .../umbraco/create/PartialViewTasksBase.cs | 6 +++--- 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/Umbraco.Core/Services/FileService.cs b/src/Umbraco.Core/Services/FileService.cs index df1a6441a8..c96365f7af 100644 --- a/src/Umbraco.Core/Services/FileService.cs +++ b/src/Umbraco.Core/Services/FileService.cs @@ -23,19 +23,21 @@ namespace Umbraco.Core.Services private readonly RepositoryFactory _repositoryFactory; private readonly IUnitOfWorkProvider _fileUowProvider; private readonly IDatabaseUnitOfWorkProvider _dataUowProvider; + private readonly IMacroService _macroService; public FileService() : this(new RepositoryFactory()) { } public FileService(RepositoryFactory repositoryFactory) - : this(new FileUnitOfWorkProvider(), new PetaPocoUnitOfWorkProvider(), repositoryFactory) + : this(new FileUnitOfWorkProvider(), new PetaPocoUnitOfWorkProvider(), repositoryFactory, new MacroService()) { } - public FileService(IUnitOfWorkProvider fileProvider, IDatabaseUnitOfWorkProvider dataProvider, RepositoryFactory repositoryFactory) + public FileService(IUnitOfWorkProvider fileProvider, IDatabaseUnitOfWorkProvider dataProvider, RepositoryFactory repositoryFactory, IMacroService macroService) { _repositoryFactory = repositoryFactory; + _macroService = macroService; _fileUowProvider = fileProvider; _dataUowProvider = dataProvider; } @@ -420,16 +422,15 @@ namespace Umbraco.Core.Services return Attempt.Succeed(partialView); } - internal static void CreatePartialViewMacro(PartialView partialView) + internal void CreatePartialViewMacro(PartialView partialView) { var name = partialView.FileName.Substring(0, (partialView.FileName.LastIndexOf('.') + 1)) .Trim('.') .SplitPascalCasing() .ToFirstUpperInvariant(); - var macroService = new MacroService(); var macro = new Macro(name, name) { ScriptPath = partialView.BasePath + partialView.FileName }; - macroService.Save(macro); + _macroService.Save(macro); } // TODO: Before making this public: How to get feedback in the UI when cancelled diff --git a/src/Umbraco.Core/Services/ServiceContext.cs b/src/Umbraco.Core/Services/ServiceContext.cs index f358e41bf3..375e1ca1ba 100644 --- a/src/Umbraco.Core/Services/ServiceContext.cs +++ b/src/Umbraco.Core/Services/ServiceContext.cs @@ -144,7 +144,7 @@ namespace Umbraco.Core.Services _dataTypeService = new Lazy(() => new DataTypeService(provider, repositoryFactory.Value)); if (_fileService == null) - _fileService = new Lazy(() => new FileService(fileProvider, provider, repositoryFactory.Value)); + _fileService = new Lazy(() => new FileService(fileProvider, provider, repositoryFactory.Value, _macroService.Value)); if (_localizationService == null) _localizationService = new Lazy(() => new LocalizationService(provider, repositoryFactory.Value)); diff --git a/src/Umbraco.Web/WebServices/SaveFileController.cs b/src/Umbraco.Web/WebServices/SaveFileController.cs index 56f52887ce..591b89e1d4 100644 --- a/src/Umbraco.Web/WebServices/SaveFileController.cs +++ b/src/Umbraco.Web/WebServices/SaveFileController.cs @@ -49,7 +49,7 @@ namespace Umbraco.Web.WebServices Content = contents, }; - var fileService = new FileService(); + var fileService = (FileService)ApplicationContext.Current.Services.FileService; var attempt = fileService.SavePartialView(partialView); if (attempt.Success == false) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/create/PartialViewTasksBase.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/create/PartialViewTasksBase.cs index fdceb238d3..313cbc3efd 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/create/PartialViewTasksBase.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/create/PartialViewTasksBase.cs @@ -64,7 +64,7 @@ namespace umbraco BasePath = BasePath }; - var fileService = new FileService(); + var fileService = (FileService)ApplicationContext.Current.Services.FileService; var attempt = fileService.CreatePartialView(model); _returnUrl = attempt.Result.ReturnUrl; @@ -79,8 +79,8 @@ namespace umbraco var fullFilePath = partialViewsFileSystem.GetFullPath(path); var model = new PartialView(fullFilePath) { BasePath = BasePath, FileName = path }; - - var fileService = new FileService(); + + var fileService = (FileService)ApplicationContext.Current.Services.FileService; return fileService.DeletePartialView(model, UmbracoEnsuredPage.CurrentUser.Id); } }