diff --git a/src/Umbraco.Core/IO/FileSystems.cs b/src/Umbraco.Core/IO/FileSystems.cs index 9749078923..061413d070 100644 --- a/src/Umbraco.Core/IO/FileSystems.cs +++ b/src/Umbraco.Core/IO/FileSystems.cs @@ -318,7 +318,7 @@ namespace Umbraco.Core.IO // validate the ctor var constructor = fsType.GetConstructors().SingleOrDefault(x - => x.GetParameters().Length == 1 && TypeHelper.IsTypeAssignableFrom(x.GetParameters().Single().ParameterType)); + => x.GetParameters().Length >= 1 && TypeHelper.IsTypeAssignableFrom(x.GetParameters().First().ParameterType)); if (constructor == null) throw new InvalidOperationException("Type " + fsType.FullName + " must inherit from FileSystemWrapper and have a constructor that accepts one parameter of type " + typeof(IFileSystem).FullName + "."); diff --git a/src/Umbraco.Core/IO/MediaFileSystem.cs b/src/Umbraco.Core/IO/MediaFileSystem.cs index b3fc2ccb61..b59d5b6924 100644 --- a/src/Umbraco.Core/IO/MediaFileSystem.cs +++ b/src/Umbraco.Core/IO/MediaFileSystem.cs @@ -6,10 +6,8 @@ using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; -using LightInject; using Umbraco.Core.Configuration; using Umbraco.Core.Configuration.UmbracoSettings; -using Umbraco.Core.Composing; using Umbraco.Core.Exceptions; using Umbraco.Core.Logging; using Umbraco.Core.Media; @@ -35,21 +33,23 @@ namespace Umbraco.Core.IO // { 500, "big-thumb" } //}; - public MediaFileSystem(IFileSystem wrapped) + public MediaFileSystem(IFileSystem wrapped, IContentSection contentConfig, ILogger logger) : base(wrapped) { + ContentConfig = contentConfig; + Logger = logger; + + // fixme - remove obsolete comments // due to how FileSystems is written at the moment, the ctor cannot be used to inject // dependencies, so we have to rely on property injection for anything we might need - ((IServiceContainer)Current.Container.ConcreteContainer).InjectProperties(this); + //((IServiceContainer)Current.Container.ConcreteContainer).InjectProperties(this); UploadAutoFillProperties = new UploadAutoFillProperties(this, Logger, ContentConfig); } - [Inject] - internal IContentSection ContentConfig { get; set; } + internal IContentSection ContentConfig { get; } - [Inject] - internal ILogger Logger { get; set; } + internal ILogger Logger { get; } internal UploadAutoFillProperties UploadAutoFillProperties { get; } diff --git a/src/Umbraco.Core/Runtime/CoreRuntimeComponent.cs b/src/Umbraco.Core/Runtime/CoreRuntimeComponent.cs index a90d5b5b4c..a9a1369a97 100644 --- a/src/Umbraco.Core/Runtime/CoreRuntimeComponent.cs +++ b/src/Umbraco.Core/Runtime/CoreRuntimeComponent.cs @@ -44,6 +44,9 @@ namespace Umbraco.Core.Runtime composition.Container.Register(); // register filesystems + + composition.Container.Register((f, wrappedFileSystem) => new MediaFileSystem(wrappedFileSystem, f.GetInstance(), f.GetInstance())); + composition.Container.RegisterSingleton(); composition.Container.RegisterSingleton(factory => factory.GetInstance().MediaFileSystem); composition.Container.RegisterSingleton(factory => factory.GetInstance().ScriptsFileSystem, Constants.Composing.FileSystems.ScriptFileSystem); diff --git a/src/Umbraco.Tests/IO/FileSystemsTests.cs b/src/Umbraco.Tests/IO/FileSystemsTests.cs index 83792b9a0b..c0f13c6e1b 100644 --- a/src/Umbraco.Tests/IO/FileSystemsTests.cs +++ b/src/Umbraco.Tests/IO/FileSystemsTests.cs @@ -33,8 +33,8 @@ namespace Umbraco.Tests.IO _container.Register(_ => Mock.Of()); _container.Register(_ => Mock.Of()); - _container.Register(); - _container.Register(); + _container.Register((f, x) => new MediaFileSystem(x, f.GetInstance(), f.GetInstance())); + _container.Register((f, x) => new NonConfiguredTypeFileSystem(x)); // make sure we start clean // because some tests will create corrupt or weird filesystems diff --git a/src/Umbraco.Tests/Models/ContentTests.cs b/src/Umbraco.Tests/Models/ContentTests.cs index 2e68873f77..41228eb89e 100644 --- a/src/Umbraco.Tests/Models/ContentTests.cs +++ b/src/Umbraco.Tests/Models/ContentTests.cs @@ -5,7 +5,8 @@ using System.Globalization; using System.IO; using System.Linq; using System.Web; -using Moq; +using Moq; +using LightInject; using NUnit.Framework; using Umbraco.Core.Cache; using Umbraco.Core.Configuration.UmbracoSettings; @@ -22,7 +23,7 @@ using Umbraco.Tests.Testing; namespace Umbraco.Tests.Models { - [TestFixture] + [TestFixture] public class ContentTests : UmbracoTestBase { public override void SetUp() @@ -36,8 +37,9 @@ namespace Umbraco.Tests.Models protected override void Compose() { base.Compose(); - + Container.Register(_ => Mock.Of()); + Container.Register((factory, fileSystem) => new MediaFileSystem(fileSystem, factory.GetInstance(), factory.GetInstance())); Container.Register(); Container.Register(_ => Mock.Of()); Container.Register(_ => Mock.Of()); diff --git a/src/Umbraco.Tests/Models/MediaXmlTest.cs b/src/Umbraco.Tests/Models/MediaXmlTest.cs index 6f28842f18..1f4eaf9d8a 100644 --- a/src/Umbraco.Tests/Models/MediaXmlTest.cs +++ b/src/Umbraco.Tests/Models/MediaXmlTest.cs @@ -29,7 +29,7 @@ namespace Umbraco.Tests.Models // reference, so static ctor runs, so event handlers register // and then, this will reset the width, height... because the file does not exist, of course ;-( - var ignored = new FileUploadPropertyEditor(Mock.Of(), new MediaFileSystem(Mock.Of())); + var ignored = new FileUploadPropertyEditor(Mock.Of(), new MediaFileSystem(Mock.Of(), Mock.Of(), Mock.Of())); var media = MockedMedia.CreateMediaImage(mediaType, -1); media.WriterId = -1; // else it's zero and that's not a user and it breaks the tests diff --git a/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs b/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs index 83d5fea1d1..8df585fb25 100644 --- a/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs +++ b/src/Umbraco.Tests/PropertyEditors/ImageCropperTest.cs @@ -72,7 +72,7 @@ namespace Umbraco.Tests.PropertyEditors container.Register(f => Mock.Of()); container.Register(f => Mock.Of()); - var mediaFileSystem = new MediaFileSystem(Mock.Of()); + var mediaFileSystem = new MediaFileSystem(Mock.Of(), Mock.Of(), Mock.Of()); var dataTypeService = new TestObjects.TestDataTypeService( new DataType(new ImageCropperPropertyEditor(Mock.Of(), mediaFileSystem, Mock.Of())) { Id = 1 }); diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects.cs b/src/Umbraco.Tests/TestHelpers/TestObjects.cs index 485cce4c0a..7e3d887d77 100644 --- a/src/Umbraco.Tests/TestHelpers/TestObjects.cs +++ b/src/Umbraco.Tests/TestHelpers/TestObjects.cs @@ -10,6 +10,7 @@ using Umbraco.Core; using Umbraco.Core.Cache; using Umbraco.Core.Composing; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Events; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -116,7 +117,7 @@ namespace Umbraco.Tests.TestHelpers if (logger == null) throw new ArgumentNullException(nameof(logger)); if (eventMessagesFactory == null) throw new ArgumentNullException(nameof(eventMessagesFactory)); - var mediaFileSystem = new MediaFileSystem(Mock.Of()); + var mediaFileSystem = new MediaFileSystem(Mock.Of(), Mock.Of(), Mock.Of()); var externalLoginService = GetLazyService(container, c => new ExternalLoginService(scopeProvider, logger, eventMessagesFactory, GetRepo(c))); var publicAccessService = GetLazyService(container, c => new PublicAccessService(scopeProvider, logger, eventMessagesFactory, GetRepo(c))); diff --git a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs index b5f3de72a4..2048b7cb58 100644 --- a/src/Umbraco.Tests/Testing/UmbracoTestBase.cs +++ b/src/Umbraco.Tests/Testing/UmbracoTestBase.cs @@ -13,6 +13,7 @@ using Umbraco.Core.Components; using Umbraco.Core.Composing; using Umbraco.Core.Composing.CompositionRoots; using Umbraco.Core.Configuration; +using Umbraco.Core.Configuration.UmbracoSettings; using Umbraco.Core.Events; using Umbraco.Core.IO; using Umbraco.Core.Logging; @@ -267,7 +268,7 @@ namespace Umbraco.Tests.Testing Container.RegisterSingleton(factory => globalSettings); Container.RegisterSingleton(factory => umbracoSettings.Content); Container.RegisterSingleton(factory => umbracoSettings.Templates); - Container.Register(factory => new MediaFileSystem(Mock.Of())); + Container.Register((factory, fileSystem) => new MediaFileSystem(fileSystem, factory.GetInstance(), factory.GetInstance())); Container.RegisterSingleton(factory => ExamineManager.Instance); // replace some stuff