Merge branch 'temp8-u4-11427-remove-propertyinjection' of https://github.com/lars-erik/Umbraco-CMS into temp8-u4-11227
This commit is contained in:
@@ -1,8 +1,12 @@
|
||||
using System;
|
||||
using LightInject;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.Repositories.Implement;
|
||||
using Umbraco.Core.Scoping;
|
||||
|
||||
namespace Umbraco.Core.Composing.CompositionRoots
|
||||
{
|
||||
@@ -36,7 +40,7 @@ namespace Umbraco.Core.Composing.CompositionRoots
|
||||
// some repositories have an annotated ctor parameter to pick the right cache helper
|
||||
|
||||
// repositories
|
||||
container.RegisterSingleton<IAuditRepository, AuditRepository>();
|
||||
container.RegisterSingleton<IAuditRepository>(f => new AuditRepository(f.GetInstance<IScopeAccessor>(), f.GetInstance<CacheHelper>(DisabledCache), f.GetInstance<ILogger>()));
|
||||
container.RegisterSingleton<IAuditEntryRepository, AuditEntryRepository>();
|
||||
container.RegisterSingleton<IContentTypeRepository, ContentTypeRepository>();
|
||||
container.RegisterSingleton<IDataTypeContainerRepository, DataTypeContainerRepository>();
|
||||
@@ -59,23 +63,30 @@ namespace Umbraco.Core.Composing.CompositionRoots
|
||||
container.RegisterSingleton<INotificationsRepository, NotificationsRepository>();
|
||||
container.RegisterSingleton<IPublicAccessRepository, PublicAccessRepository>();
|
||||
container.RegisterSingleton<IRedirectUrlRepository, RedirectUrlRepository>();
|
||||
container.RegisterSingleton<IRelationRepository, RelationRepository>();
|
||||
container.RegisterSingleton<IRelationRepository>(f => new RelationRepository(f.GetInstance<IScopeAccessor>(), f.GetInstance<CacheHelper>(DisabledCache), f.GetInstance<ILogger>(), f.GetInstance<IRelationTypeRepository>()));
|
||||
container.RegisterSingleton<IRelationTypeRepository, RelationTypeRepository>();
|
||||
container.RegisterSingleton<IServerRegistrationRepository, ServerRegistrationRepository>();
|
||||
container.RegisterSingleton<ITagRepository, TagRepository>();
|
||||
container.RegisterSingleton<ITaskRepository, TaskRepository>();
|
||||
container.RegisterSingleton<ITaskTypeRepository, TaskTypeRepository>();
|
||||
container.RegisterSingleton<ITemplateRepository, TemplateRepository>();
|
||||
container.RegisterSingleton<ITaskRepository>(f => new TaskRepository(f.GetInstance<IScopeAccessor>(), f.GetInstance<CacheHelper>(DisabledCache), f.GetInstance<ILogger>()));
|
||||
container.RegisterSingleton<ITaskTypeRepository>(f => new TaskTypeRepository(f.GetInstance<IScopeAccessor>(), f.GetInstance<CacheHelper>(DisabledCache), f.GetInstance<ILogger>()));
|
||||
container.RegisterSingleton<ITemplateRepository>(f => new TemplateRepository(
|
||||
f.GetInstance<IScopeAccessor>(),
|
||||
f.GetInstance<CacheHelper>(),
|
||||
f.GetInstance<ILogger>(),
|
||||
f.GetInstance<ITemplatesSection>(),
|
||||
f.GetInstance<IFileSystem>(Constants.Composing.FileSystems.MasterpageFileSystem),
|
||||
f.GetInstance<IFileSystem>(Constants.Composing.FileSystems.ViewFileSystem)
|
||||
));
|
||||
container.RegisterSingleton<IUserGroupRepository, UserGroupRepository>();
|
||||
container.RegisterSingleton<IUserRepository, UserRepository>();
|
||||
container.RegisterSingleton<IConsentRepository, ConsentRepository>();
|
||||
|
||||
// repositories that depend on a filesystem
|
||||
// these have an annotated ctor parameter to pick the right file system
|
||||
container.RegisterSingleton<IPartialViewMacroRepository, PartialViewMacroRepository>();
|
||||
container.RegisterSingleton<IPartialViewRepository, PartialViewRepository>();
|
||||
container.RegisterSingleton<IScriptRepository, ScriptRepository>();
|
||||
container.RegisterSingleton<IStylesheetRepository, StylesheetRepository>();
|
||||
container.RegisterSingleton<IPartialViewMacroRepository>(f => new PartialViewMacroRepository(f.GetInstance<IFileSystem>("PartialViewMacroFileSystem")));
|
||||
container.RegisterSingleton<IPartialViewRepository>(f => new PartialViewRepository(f.GetInstance<IFileSystem>("PartialViewFileSystem")));
|
||||
container.RegisterSingleton<IScriptRepository>(f => new ScriptRepository(f.GetInstance<IFileSystem>("ScriptFileSystem"), f.GetInstance<IContentSection>()));
|
||||
container.RegisterSingleton<IStylesheetRepository>(f => new StylesheetRepository(f.GetInstance<IFileSystem>("StylesheetFileSystem")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Umbraco.Core.Composing
|
||||
/// </remarks>
|
||||
public static class Current
|
||||
{
|
||||
private static IServiceContainer _container;
|
||||
private static IContainer _container;
|
||||
|
||||
private static IShortStringHelper _shortStringHelper;
|
||||
private static ILogger _logger;
|
||||
@@ -38,7 +38,7 @@ namespace Umbraco.Core.Composing
|
||||
/// <summary>
|
||||
/// Gets or sets the DI container.
|
||||
/// </summary>
|
||||
internal static IServiceContainer Container
|
||||
internal static IContainer Container
|
||||
{
|
||||
get
|
||||
{
|
||||
|
||||
21
src/Umbraco.Core/Composing/IContainer.cs
Normal file
21
src/Umbraco.Core/Composing/IContainer.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Umbraco.Core.Composing
|
||||
{
|
||||
public interface IContainer
|
||||
{
|
||||
T TryGetInstance<T>();
|
||||
T GetInstance<T>();
|
||||
object GetInstance(Type parameterType);
|
||||
object ConcreteContainer { get; }
|
||||
void RegisterSingleton<T>(Func<IContainer, T> factory);
|
||||
void Register<T>(Func<IContainer, T> factory);
|
||||
void Register<T, TService>(Func<IContainer, T, TService> factory);
|
||||
T RegisterCollectionBuilder<T>();
|
||||
T GetInstance<T>(object[] args);
|
||||
}
|
||||
}
|
||||
61
src/Umbraco.Core/Composing/LightInject/ContainerAdapter.cs
Normal file
61
src/Umbraco.Core/Composing/LightInject/ContainerAdapter.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using LightInject;
|
||||
|
||||
namespace Umbraco.Core.Composing.LightInject
|
||||
{
|
||||
public class ContainerAdapter : IContainer
|
||||
{
|
||||
private readonly IServiceContainer container;
|
||||
|
||||
public object ConcreteContainer => container;
|
||||
|
||||
public void RegisterSingleton<T>(Func<IContainer, T> factory)
|
||||
{
|
||||
container.RegisterSingleton(f => factory(this));
|
||||
}
|
||||
|
||||
public void Register<T>(Func<IContainer, T> factory)
|
||||
{
|
||||
container.Register(f => factory(this));
|
||||
}
|
||||
|
||||
public void Register<T, TService>(Func<IContainer, T, TService> factory)
|
||||
{
|
||||
container.Register<T, TService>((f, x) => factory(this, x));
|
||||
}
|
||||
|
||||
public T RegisterCollectionBuilder<T>()
|
||||
{
|
||||
return container.RegisterCollectionBuilder<T>();
|
||||
}
|
||||
|
||||
public ContainerAdapter(IServiceContainer container)
|
||||
{
|
||||
this.container = container;
|
||||
}
|
||||
|
||||
public T TryGetInstance<T>()
|
||||
{
|
||||
return container.TryGetInstance<T>();
|
||||
}
|
||||
|
||||
public T GetInstance<T>()
|
||||
{
|
||||
return container.GetInstance<T>();
|
||||
}
|
||||
|
||||
public T GetInstance<T>(object[] args)
|
||||
{
|
||||
return (T)container.GetInstance(typeof(T), args);
|
||||
}
|
||||
|
||||
public object GetInstance(Type type)
|
||||
{
|
||||
return container.GetInstance(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ namespace Umbraco.Core.Composing
|
||||
container.Register<IServiceContainer>(_ => container);
|
||||
|
||||
// configure the current container
|
||||
Current.Container = container;
|
||||
Current.Container = new LightInject.ContainerAdapter(container);
|
||||
}
|
||||
|
||||
private class AssemblyScanner : IAssemblyScanner
|
||||
|
||||
@@ -302,7 +302,11 @@ namespace Umbraco.Core.IO
|
||||
// could be optimized by having FileSystemWrapper inherit from ShadowWrapper, maybe
|
||||
var innerFs = GetUnderlyingFileSystemNoCache(alias, fallback);
|
||||
var shadowWrapper = new ShadowWrapper(innerFs, "typed/" + alias, () => IsScoped());
|
||||
var fs = (IFileSystem) Activator.CreateInstance(typeof(TFileSystem), shadowWrapper);
|
||||
|
||||
// fixme - switch to using container. where are these registered?
|
||||
|
||||
//var fs = (IFileSystem) Activator.CreateInstance(typeof(TFileSystem), shadowWrapper);
|
||||
var fs = Current.Container.GetInstance<TFileSystem>(new object[] { (IFileSystem)shadowWrapper });
|
||||
_wrappers.Add(shadowWrapper); // keeping a reference to the wrapper
|
||||
return fs;
|
||||
});
|
||||
@@ -314,7 +318,7 @@ namespace Umbraco.Core.IO
|
||||
|
||||
// validate the ctor
|
||||
var constructor = fsType.GetConstructors().SingleOrDefault(x
|
||||
=> x.GetParameters().Length == 1 && TypeHelper.IsTypeAssignableFrom<IFileSystem>(x.GetParameters().Single().ParameterType));
|
||||
=> x.GetParameters().Length >= 1 && TypeHelper.IsTypeAssignableFrom<IFileSystem>(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 + ".");
|
||||
|
||||
|
||||
@@ -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.IO.MediaPathSchemes;
|
||||
using Umbraco.Core.Logging;
|
||||
@@ -25,24 +23,21 @@ namespace Umbraco.Core.IO
|
||||
[FileSystemProvider("media")]
|
||||
public class MediaFileSystem : FileSystemWrapper
|
||||
{
|
||||
public MediaFileSystem(IFileSystem wrapped)
|
||||
public MediaFileSystem(IFileSystem wrapped, IContentSection contentConfig, IMediaPathScheme mediaPathScheme, ILogger logger)
|
||||
: base(wrapped)
|
||||
{
|
||||
// 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
|
||||
Current.Container.InjectProperties(this);
|
||||
ContentConfig = contentConfig;
|
||||
Logger = logger;
|
||||
MediaPathScheme = mediaPathScheme;
|
||||
|
||||
UploadAutoFillProperties = new UploadAutoFillProperties(this, Logger, ContentConfig);
|
||||
}
|
||||
|
||||
[Inject]
|
||||
internal IMediaPathScheme MediaPathScheme { get; set; }
|
||||
}
|
||||
|
||||
[Inject]
|
||||
internal IContentSection ContentConfig { get; set; }
|
||||
private IMediaPathScheme MediaPathScheme { get; }
|
||||
|
||||
[Inject]
|
||||
internal ILogger Logger { get; set; }
|
||||
private IContentSection ContentConfig { get; }
|
||||
|
||||
private ILogger Logger { get; }
|
||||
|
||||
internal UploadAutoFillProperties UploadAutoFillProperties { get; }
|
||||
|
||||
@@ -104,8 +99,8 @@ namespace Umbraco.Core.IO
|
||||
if (FileExists(file) == false) return;
|
||||
DeleteFile(file);
|
||||
|
||||
var directory = MediaPathScheme.GetDeleteDirectory(file);
|
||||
if (!directory.IsNullOrWhiteSpace())
|
||||
var directory = MediaPathScheme.GetDeleteDirectory(file);
|
||||
if (!directory.IsNullOrWhiteSpace())
|
||||
DeleteDirectory(directory, true);
|
||||
}
|
||||
catch (Exception e)
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using LightInject;
|
||||
using NPoco;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing.CompositionRoots;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.DatabaseModelDefinitions;
|
||||
@@ -16,7 +14,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
{
|
||||
internal class AuditRepository : NPocoRepositoryBase<int, IAuditItem>, IAuditRepository
|
||||
{
|
||||
public AuditRepository(IScopeAccessor scopeAccessor, [Inject(RepositoryCompositionRoot.DisabledCache)] CacheHelper cache, ILogger logger)
|
||||
public AuditRepository(IScopeAccessor scopeAccessor, CacheHelper cache, ILogger logger)
|
||||
: base(scopeAccessor, cache, logger)
|
||||
{ }
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using LightInject;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
@@ -7,7 +6,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
internal class PartialViewMacroRepository : PartialViewRepository, IPartialViewMacroRepository
|
||||
{
|
||||
|
||||
public PartialViewMacroRepository([Inject("PartialViewMacroFileSystem")] IFileSystem fileSystem)
|
||||
public PartialViewMacroRepository(IFileSystem fileSystem)
|
||||
: base(fileSystem)
|
||||
{ }
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using LightInject;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
@@ -10,7 +9,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
{
|
||||
internal class PartialViewRepository : FileRepository<string, IPartialView>, IPartialViewRepository
|
||||
{
|
||||
public PartialViewRepository([Inject("PartialViewFileSystem")] IFileSystem fileSystem)
|
||||
public PartialViewRepository(IFileSystem fileSystem)
|
||||
: base(fileSystem)
|
||||
{ }
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using LightInject;
|
||||
using NPoco;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing.CompositionRoots;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Entities;
|
||||
@@ -22,7 +20,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
{
|
||||
private readonly IRelationTypeRepository _relationTypeRepository;
|
||||
|
||||
public RelationRepository(IScopeAccessor scopeAccessor, [Inject(RepositoryCompositionRoot.DisabledCache)] CacheHelper cache, ILogger logger, IRelationTypeRepository relationTypeRepository)
|
||||
public RelationRepository(IScopeAccessor scopeAccessor, CacheHelper cache, ILogger logger, IRelationTypeRepository relationTypeRepository)
|
||||
: base(scopeAccessor, cache, logger)
|
||||
{
|
||||
_relationTypeRepository = relationTypeRepository;
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using LightInject;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models;
|
||||
@@ -16,7 +15,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
{
|
||||
private readonly IContentSection _contentConfig;
|
||||
|
||||
public ScriptRepository([Inject("ScriptFileSystem")] IFileSystem fileSystem, IContentSection contentConfig)
|
||||
public ScriptRepository(IFileSystem fileSystem, IContentSection contentConfig)
|
||||
: base(fileSystem)
|
||||
{
|
||||
_contentConfig = contentConfig ?? throw new ArgumentNullException(nameof(contentConfig));
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using LightInject;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Models;
|
||||
|
||||
@@ -12,7 +11,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
/// </summary>
|
||||
internal class StylesheetRepository : FileRepository<string, Stylesheet>, IStylesheetRepository
|
||||
{
|
||||
public StylesheetRepository([Inject("StylesheetFileSystem")] IFileSystem fileSystem)
|
||||
public StylesheetRepository(IFileSystem fileSystem)
|
||||
: base(fileSystem)
|
||||
{ }
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using LightInject;
|
||||
using NPoco;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing.CompositionRoots;
|
||||
using Umbraco.Core.Exceptions;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
@@ -17,7 +15,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
{
|
||||
internal class TaskRepository : NPocoRepositoryBase<int, Task>, ITaskRepository
|
||||
{
|
||||
public TaskRepository(IScopeAccessor scopeAccessor, [Inject(RepositoryCompositionRoot.DisabledCache)] CacheHelper cache, ILogger logger)
|
||||
public TaskRepository(IScopeAccessor scopeAccessor, CacheHelper cache, ILogger logger)
|
||||
: base(scopeAccessor, cache, logger)
|
||||
{ }
|
||||
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using LightInject;
|
||||
using NPoco;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing.CompositionRoots;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
@@ -16,7 +14,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
{
|
||||
internal class TaskTypeRepository : NPocoRepositoryBase<int, TaskType>, ITaskTypeRepository
|
||||
{
|
||||
public TaskTypeRepository(IScopeAccessor scopeAccessor, [Inject(RepositoryCompositionRoot.DisabledCache)] CacheHelper cache, ILogger logger)
|
||||
public TaskTypeRepository(IScopeAccessor scopeAccessor, CacheHelper cache, ILogger logger)
|
||||
: base(scopeAccessor, cache, logger)
|
||||
{ }
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using LightInject;
|
||||
using NPoco;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
@@ -31,8 +30,8 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
private readonly MasterPageHelper _masterPageHelper;
|
||||
|
||||
public TemplateRepository(IScopeAccessor scopeAccessor, CacheHelper cache, ILogger logger, ITemplatesSection templateConfig,
|
||||
[Inject(Constants.Composing.FileSystems.MasterpageFileSystem)] IFileSystem masterpageFileSystem,
|
||||
[Inject(Constants.Composing.FileSystems.ViewFileSystem)] IFileSystem viewFileSystem)
|
||||
IFileSystem masterpageFileSystem,
|
||||
IFileSystem viewFileSystem)
|
||||
: base(scopeAccessor, cache, logger)
|
||||
{
|
||||
_masterpagesFileSystem = masterpageFileSystem;
|
||||
|
||||
@@ -45,6 +45,10 @@ namespace Umbraco.Core.Runtime
|
||||
composition.Container.Register<DatabaseBuilder>();
|
||||
|
||||
// register filesystems
|
||||
|
||||
composition.Container.Register<IFileSystem, MediaFileSystem>((f, wrappedFileSystem) => new MediaFileSystem(wrappedFileSystem, f.GetInstance<IContentSection>(), f.GetInstance<ILogger>()));
|
||||
composition.Container.RegisterConstructorDependency((factory, parameterInfo) => factory.GetInstance<FileSystems>().MediaFileSystem);
|
||||
|
||||
composition.Container.RegisterSingleton<FileSystems>();
|
||||
composition.Container.RegisterSingleton(factory => factory.GetInstance<FileSystems>().MediaFileSystem);
|
||||
composition.Container.RegisterSingleton(factory => factory.GetInstance<FileSystems>().ScriptsFileSystem, Constants.Composing.FileSystems.ScriptFileSystem);
|
||||
|
||||
@@ -166,9 +166,11 @@
|
||||
<Compile Include="Composing\HideFromTypeFinderAttribute.cs" />
|
||||
<Compile Include="Composing\IBuilderCollection.cs" />
|
||||
<Compile Include="Composing\ICollectionBuilder.cs" />
|
||||
<Compile Include="Composing\IContainer.cs" />
|
||||
<Compile Include="Composing\IDiscoverable.cs" />
|
||||
<Compile Include="Composing\LazyCollectionBuilderBase.cs" />
|
||||
<Compile Include="Composing\LightInjectExtensions.cs" />
|
||||
<Compile Include="Composing\LightInject\ContainerAdapter.cs" />
|
||||
<Compile Include="Composing\MixedLightInjectScopeManagerProvider.cs" />
|
||||
<Compile Include="Composing\OrderedCollectionBuilderBase.cs" />
|
||||
<Compile Include="Composing\TypeFinder.cs" />
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Umbraco.Tests.CoreThings
|
||||
var globalSettings = SettingsForTests.GenerateMockGlobalSettings();
|
||||
container.Setup(x => x.GetInstance(typeof (TypeLoader))).Returns(
|
||||
new TypeLoader(NullCacheProvider.Instance, globalSettings, new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>())));
|
||||
Current.Container = container.Object;
|
||||
Current.Container = new Core.Composing.LightInject.ContainerAdapter(container.Object);
|
||||
|
||||
Udi.ResetUdiTypes();
|
||||
}
|
||||
|
||||
@@ -33,6 +33,9 @@ namespace Umbraco.Tests.IO
|
||||
_container.Register(_ => Mock.Of<IDataTypeService>());
|
||||
_container.Register(_ => Mock.Of<IContentSection>());
|
||||
|
||||
_container.Register<IFileSystem, MediaFileSystem>((f, x) => new MediaFileSystem(x, f.GetInstance<IContentSection>(), f.GetInstance<ILogger>()));
|
||||
_container.Register<IFileSystem, NonConfiguredTypeFileSystem>((f, x) => new NonConfiguredTypeFileSystem(x));
|
||||
|
||||
// make sure we start clean
|
||||
// because some tests will create corrupt or weird filesystems
|
||||
FileSystems.Reset();
|
||||
|
||||
@@ -22,6 +22,7 @@ using static Umbraco.Tests.Cache.DistributedCache.DistributedCacheTests;
|
||||
namespace Umbraco.Tests.Integration
|
||||
{
|
||||
[TestFixture]
|
||||
[Category("Slow")]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
||||
public class ContentEventsTests : TestWithSomeContentBase
|
||||
{
|
||||
|
||||
@@ -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<ILogger>());
|
||||
Container.Register<IFileSystem, MediaFileSystem>((factory, fileSystem) => new MediaFileSystem(fileSystem, factory.GetInstance<IContentSection>(), factory.GetInstance<ILogger>()));
|
||||
Container.Register<FileSystems>();
|
||||
Container.Register(_ => Mock.Of<IDataTypeService>());
|
||||
Container.Register(_ => Mock.Of<IContentSection>());
|
||||
|
||||
@@ -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<ILogger>(), new MediaFileSystem(Mock.Of<IFileSystem>()));
|
||||
var ignored = new FileUploadPropertyEditor(Mock.Of<ILogger>(), new MediaFileSystem(Mock.Of<IFileSystem>(), Mock.Of<IContentSection>(), Mock.Of<ILogger>()));
|
||||
|
||||
var media = MockedMedia.CreateMediaImage(mediaType, -1);
|
||||
media.WriterId = -1; // else it's zero and that's not a user and it breaks the tests
|
||||
|
||||
@@ -4,6 +4,7 @@ using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Composing.LightInject;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
@@ -29,7 +30,7 @@ namespace Umbraco.Tests.Models
|
||||
|
||||
Current.Reset();
|
||||
var container = Mock.Of<IServiceContainer>();
|
||||
Current.Container = container;
|
||||
Current.Container = new ContainerAdapter(container);
|
||||
|
||||
var dataEditors = new DataEditorCollection(new IDataEditor[]
|
||||
{
|
||||
|
||||
@@ -72,7 +72,7 @@ namespace Umbraco.Tests.PropertyEditors
|
||||
|
||||
container.Register<ILogger, PerContainerLifetime>(f => Mock.Of<ILogger>());
|
||||
container.Register<IContentSection, PerContainerLifetime>(f => Mock.Of<IContentSection>());
|
||||
var mediaFileSystem = new MediaFileSystem(Mock.Of<IFileSystem>());
|
||||
var mediaFileSystem = new MediaFileSystem(Mock.Of<IFileSystem>(), Mock.Of<IContentSection>(), Mock.Of<ILogger>());
|
||||
|
||||
var dataTypeService = new TestObjects.TestDataTypeService(
|
||||
new DataType(new ImageCropperPropertyEditor(Mock.Of<ILogger>(), mediaFileSystem, Mock.Of<IContentSection>())) { Id = 1 });
|
||||
|
||||
@@ -6,6 +6,7 @@ using LightInject;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
@@ -17,7 +18,10 @@ using Umbraco.Web.Routing;
|
||||
using Umbraco.Web.WebApi;
|
||||
using Umbraco.Core.Strings;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.PublishedContent;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Tests.Testing.Objects.Accessors;
|
||||
@@ -182,6 +186,10 @@ namespace Umbraco.Tests.Routing
|
||||
/// </summary>
|
||||
public class CustomDocumentController : RenderMvcController
|
||||
{
|
||||
public CustomDocumentController(IGlobalSettings globalSettings, UmbracoContext umbracoContext, IUmbracoDatabaseFactory databaseFactory, ServiceContext services, CacheHelper applicationCache, ILogger logger, ProfilingLogger profilingLogger) : base(globalSettings, umbracoContext, databaseFactory, services, applicationCache, logger, profilingLogger)
|
||||
{
|
||||
}
|
||||
|
||||
public ActionResult HomePage(ContentModel model)
|
||||
{
|
||||
return View();
|
||||
|
||||
@@ -10,8 +10,16 @@ using Umbraco.Web;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Sync;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
|
||||
// fixme - abstract container
|
||||
using LightInject;
|
||||
|
||||
namespace Umbraco.Tests.Routing
|
||||
{
|
||||
[TestFixture]
|
||||
@@ -23,13 +31,23 @@ namespace Umbraco.Tests.Routing
|
||||
public override void SetUp()
|
||||
{
|
||||
base.SetUp();
|
||||
|
||||
|
||||
// fixme - be able to get the UmbracoModule from the container. any reason settings were from testobjects?
|
||||
//create the module
|
||||
_module = new UmbracoModule
|
||||
{
|
||||
GlobalSettings = TestObjects.GetGlobalSettings(),
|
||||
Logger = Mock.Of<ILogger>()
|
||||
};
|
||||
_module = new UmbracoModule
|
||||
(
|
||||
TestObjects.GetUmbracoSettings(),
|
||||
TestObjects.GetGlobalSettings(),
|
||||
Mock.Of<IUmbracoContextAccessor>(),
|
||||
Container.GetInstance<IPublishedSnapshotService>(),
|
||||
Container.GetInstance<IUserService>(),
|
||||
new UrlProviderCollection(new IUrlProvider[0]),
|
||||
Container.GetInstance<IRuntimeState>(),
|
||||
Mock.Of<ILogger>(),
|
||||
null, // fixme - PublishedRouter complexities...
|
||||
Container.GetInstance<IUmbracoDatabaseFactory>(),
|
||||
Mock.Of<IVariationContextAccessor>()
|
||||
);
|
||||
var runtime = new RuntimeState(_module.Logger, new Lazy<IServerRegistrar>(), new Lazy<MainDom>(), Mock.Of<IUmbracoSettingsSection>(), _module.GlobalSettings);
|
||||
|
||||
_module.Runtime = runtime;
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace Umbraco.Tests.Scheduling
|
||||
{
|
||||
[TestFixture]
|
||||
[Timeout(30000)]
|
||||
[Category("Slow")]
|
||||
public class BackgroundTaskRunnerTests
|
||||
{
|
||||
private ILogger _logger;
|
||||
|
||||
@@ -13,6 +13,7 @@ using Umbraco.Core.Scoping;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.TestHelpers.Entities;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Composing.LightInject;
|
||||
using Umbraco.Core.Persistence.Mappers;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
@@ -31,9 +32,14 @@ namespace Umbraco.Tests.Scoping
|
||||
DoThing2 = null;
|
||||
DoThing3 = null;
|
||||
|
||||
Current.Container = new ServiceContainer();
|
||||
var lightinjectContainer = new ServiceContainer();
|
||||
Current.Container = new ContainerAdapter(lightinjectContainer);
|
||||
|
||||
_testObjects = new TestObjects(lightinjectContainer);
|
||||
|
||||
// fixme - move to container factory?
|
||||
Current.Container.RegisterSingleton(f => (IServiceContainer)Current.Container.ConcreteContainer);
|
||||
|
||||
_testObjects = new TestObjects(Current.Container);
|
||||
Current.Container.RegisterSingleton(f => Current.Container);
|
||||
Current.Container.RegisterSingleton(factory => new FileSystems(factory.TryGetInstance<ILogger>()));
|
||||
Current.Container.RegisterCollectionBuilder<MapperCollectionBuilder>();
|
||||
|
||||
@@ -34,6 +34,7 @@ namespace Umbraco.Tests.Services
|
||||
/// as well as configuration.
|
||||
/// </summary>
|
||||
[TestFixture]
|
||||
[Category("Slow")]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, PublishedRepositoryEvents = true, WithApplication = true)]
|
||||
public class ContentServiceTests : TestWithSomeContentBase
|
||||
{
|
||||
|
||||
@@ -19,6 +19,7 @@ using Umbraco.Tests.Testing;
|
||||
namespace Umbraco.Tests.Services
|
||||
{
|
||||
[TestFixture]
|
||||
[Category("Slow")]
|
||||
[Apartment(ApartmentState.STA)]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, PublishedRepositoryEvents = true)]
|
||||
public class ContentTypeServiceTests : TestWithSomeContentBase
|
||||
|
||||
@@ -16,6 +16,7 @@ using LightInject;
|
||||
namespace Umbraco.Tests.Services.Importing
|
||||
{
|
||||
[TestFixture]
|
||||
[Category("Slow")]
|
||||
[Apartment(ApartmentState.STA)]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest)]
|
||||
public class PackageImportTests : TestWithSomeContentBase
|
||||
|
||||
@@ -24,6 +24,7 @@ using Umbraco.Web.Security.Providers;
|
||||
namespace Umbraco.Tests.Services
|
||||
{
|
||||
[TestFixture]
|
||||
[Category("Slow")]
|
||||
[Apartment(ApartmentState.STA)]
|
||||
[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, PublishedRepositoryEvents = true, WithApplication = true)]
|
||||
public class MemberServiceTests : TestWithSomeContentBase
|
||||
|
||||
@@ -29,6 +29,7 @@ using Umbraco.Web.Security;
|
||||
using Umbraco.Web.WebApi;
|
||||
using LightInject;
|
||||
using System.Globalization;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Tests.Testing.Objects.Accessors;
|
||||
|
||||
namespace Umbraco.Tests.TestHelpers.ControllerTesting
|
||||
@@ -157,7 +158,7 @@ namespace Umbraco.Tests.TestHelpers.ControllerTesting
|
||||
urlHelper.Setup(provider => provider.GetUrl(It.IsAny<UmbracoContext>(), It.IsAny<IPublishedContent>(), It.IsAny<UrlProviderMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
|
||||
.Returns("/hello/world/1234");
|
||||
|
||||
var membershipHelper = new MembershipHelper(umbCtx, Mock.Of<MembershipProvider>(), Mock.Of<RoleProvider>());
|
||||
var membershipHelper = new MembershipHelper(new TestUmbracoContextAccessor(umbCtx), Mock.Of<MembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IUserService>(), Mock.Of<IPublicAccessService>(), Mock.Of<CacheHelper>(), Mock.Of<ILogger>(), null);
|
||||
|
||||
var mockedTypedContent = Mock.Of<IPublishedContentQuery>();
|
||||
|
||||
|
||||
@@ -47,7 +47,8 @@ namespace Umbraco.Tests.TestHelpers.Stubs
|
||||
var allParams = ctor.GetParameters().ToArray();
|
||||
foreach (var parameter in allParams)
|
||||
{
|
||||
var found = possibleParams.SingleOrDefault(x => x.GetType() == parameter.ParameterType);
|
||||
var found = possibleParams.SingleOrDefault(x => x.GetType() == parameter.ParameterType)
|
||||
?? Current.Container.GetInstance(parameter.ParameterType);
|
||||
if (found != null) args.Add(found);
|
||||
}
|
||||
if (args.Count == allParams.Length)
|
||||
|
||||
@@ -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<IFileSystem>());
|
||||
var mediaFileSystem = new MediaFileSystem(Mock.Of<IFileSystem>(), Mock.Of<IContentSection>(), Mock.Of<ILogger>());
|
||||
|
||||
var externalLoginService = GetLazyService<IExternalLoginService>(container, c => new ExternalLoginService(scopeProvider, logger, eventMessagesFactory, GetRepo<IExternalLoginRepository>(c)));
|
||||
var publicAccessService = GetLazyService<IPublicAccessService>(container, c => new PublicAccessService(scopeProvider, logger, eventMessagesFactory, GetRepo<IPublicAccessRepository>(c)));
|
||||
|
||||
@@ -5,5 +5,14 @@ namespace Umbraco.Tests.Testing.Objects.Accessors
|
||||
public class TestUmbracoContextAccessor : IUmbracoContextAccessor
|
||||
{
|
||||
public UmbracoContext UmbracoContext { get; set; }
|
||||
|
||||
public TestUmbracoContextAccessor()
|
||||
{
|
||||
}
|
||||
|
||||
public TestUmbracoContextAccessor(UmbracoContext umbracoContext)
|
||||
{
|
||||
UmbracoContext = umbracoContext;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Dictionary;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Services;
|
||||
@@ -65,7 +66,7 @@ namespace Umbraco.Tests.Testing.TestingTests
|
||||
Mock.Of<IDataTypeService>(),
|
||||
Mock.Of<ICultureDictionary>(),
|
||||
Mock.Of<IUmbracoComponentRenderer>(),
|
||||
new MembershipHelper(umbracoContext, Mock.Of<MembershipProvider>(), Mock.Of<RoleProvider>()),
|
||||
new MembershipHelper(new TestUmbracoContextAccessor(umbracoContext), Mock.Of<MembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IUserService>(), Mock.Of<IPublicAccessService>(), Mock.Of<CacheHelper>(), Mock.Of<ILogger>(), null),
|
||||
new ServiceContext(),
|
||||
CacheHelper.CreateDisabledCacheHelper());
|
||||
Assert.Pass();
|
||||
|
||||
@@ -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,11 @@ 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<IFileSystem>()));
|
||||
|
||||
// fixme - The whole MediaFileSystem coupling thing seems broken.
|
||||
Container.Register<IFileSystem, MediaFileSystem>((factory, fileSystem) => new MediaFileSystem(fileSystem, factory.GetInstance<IContentSection>(), factory.GetInstance<ILogger>()));
|
||||
Container.RegisterConstructorDependency((factory, parameterInfo) => factory.GetInstance<FileSystems>().MediaFileSystem);
|
||||
|
||||
Container.RegisterSingleton<IExamineManager>(factory => ExamineManager.Instance);
|
||||
|
||||
// replace some stuff
|
||||
|
||||
@@ -54,8 +54,8 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
public class Plugin1Controller : PluginController
|
||||
{
|
||||
public Plugin1Controller(UmbracoContext umbracoContext)
|
||||
: base(umbracoContext, null, null, null, null, null)
|
||||
{
|
||||
UmbracoContext = umbracoContext;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,8 +63,8 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
public class Plugin2Controller : PluginController
|
||||
{
|
||||
public Plugin2Controller(UmbracoContext umbracoContext)
|
||||
: base(umbracoContext, null, null, null, null, null)
|
||||
{
|
||||
UmbracoContext = umbracoContext;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,16 +72,16 @@ namespace Umbraco.Tests.Web.Controllers
|
||||
public class Plugin3Controller : PluginController
|
||||
{
|
||||
public Plugin3Controller(UmbracoContext umbracoContext)
|
||||
: base(umbracoContext, null, null, null, null, null)
|
||||
{
|
||||
UmbracoContext = umbracoContext;
|
||||
}
|
||||
}
|
||||
|
||||
public class Plugin4Controller : PluginController
|
||||
{
|
||||
public Plugin4Controller(UmbracoContext umbracoContext)
|
||||
: base(umbracoContext, null, null, null, null, null)
|
||||
{
|
||||
UmbracoContext = umbracoContext;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Profiling;
|
||||
@@ -17,12 +18,12 @@ using Umbraco.Tests.TestHelpers;
|
||||
using Umbraco.Tests.TestHelpers.Stubs;
|
||||
using Umbraco.Tests.Testing.Objects.Accessors;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
using Umbraco.Web.Security;
|
||||
using Current = Umbraco.Web.Composing.Current;
|
||||
|
||||
namespace Umbraco.Tests.Web.Mvc
|
||||
{
|
||||
@@ -33,6 +34,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
public void SetUp()
|
||||
{
|
||||
Current.UmbracoContextAccessor = new TestUmbracoContextAccessor();
|
||||
Core.Composing.Current.Container = Mock.Of<IContainer>();
|
||||
}
|
||||
|
||||
[TearDown]
|
||||
@@ -156,7 +158,8 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
}
|
||||
|
||||
public class MatchesDefaultIndexController : RenderMvcController
|
||||
{ }
|
||||
{
|
||||
}
|
||||
|
||||
public class MatchesOverriddenIndexController : RenderMvcController
|
||||
{
|
||||
|
||||
@@ -7,8 +7,10 @@ using System.Web.Security;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Dictionary;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Tests.TestHelpers;
|
||||
@@ -16,11 +18,11 @@ using Umbraco.Tests.TestHelpers.Stubs;
|
||||
using Umbraco.Tests.Testing;
|
||||
using Umbraco.Tests.Testing.Objects.Accessors;
|
||||
using Umbraco.Web;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
using Umbraco.Web.Routing;
|
||||
using Umbraco.Web.Security;
|
||||
using Current = Umbraco.Web.Composing.Current;
|
||||
|
||||
namespace Umbraco.Tests.Web.Mvc
|
||||
{
|
||||
@@ -49,7 +51,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
new TestVariationContextAccessor(),
|
||||
true);
|
||||
|
||||
var ctrl = new TestSurfaceController { UmbracoContext = umbracoContext };
|
||||
var ctrl = new TestSurfaceController(umbracoContext);
|
||||
|
||||
var result = ctrl.Index();
|
||||
|
||||
@@ -71,7 +73,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
new TestVariationContextAccessor(),
|
||||
true);
|
||||
|
||||
var ctrl = new TestSurfaceController { UmbracoContext = umbCtx };
|
||||
var ctrl = new TestSurfaceController(umbCtx);
|
||||
|
||||
Assert.IsNotNull(ctrl.UmbracoContext);
|
||||
}
|
||||
@@ -91,7 +93,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
new TestVariationContextAccessor(),
|
||||
true);
|
||||
|
||||
var controller = new TestSurfaceController { UmbracoContext = umbracoContext };
|
||||
var controller = new TestSurfaceController(umbracoContext);
|
||||
Container.Register(_ => umbracoContext);
|
||||
Container.InjectProperties(controller);
|
||||
|
||||
@@ -128,11 +130,11 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
Mock.Of<IDataTypeService>(),
|
||||
Mock.Of<ICultureDictionary>(),
|
||||
Mock.Of<IUmbracoComponentRenderer>(),
|
||||
new MembershipHelper(umbracoContext, Mock.Of<MembershipProvider>(), Mock.Of<RoleProvider>()),
|
||||
new MembershipHelper(new TestUmbracoContextAccessor(umbracoContext), Mock.Of<MembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IUserService>(), Mock.Of<IPublicAccessService>(), Mock.Of<CacheHelper>(), Mock.Of<ILogger>(), null),
|
||||
new ServiceContext(),
|
||||
CacheHelper.CreateDisabledCacheHelper());
|
||||
|
||||
var ctrl = new TestSurfaceController { UmbracoContext = umbracoContext, Umbraco = helper };
|
||||
var ctrl = new TestSurfaceController(umbracoContext, helper);
|
||||
var result = ctrl.GetContent(2) as PublishedContentResult;
|
||||
|
||||
Assert.IsNotNull(result);
|
||||
@@ -171,7 +173,7 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
var routeData = new RouteData();
|
||||
routeData.DataTokens.Add(Core.Constants.Web.UmbracoRouteDefinitionDataToken, routeDefinition);
|
||||
|
||||
var ctrl = new TestSurfaceController { UmbracoContext = umbracoContext, Umbraco = new UmbracoHelper() };
|
||||
var ctrl = new TestSurfaceController(umbracoContext, new UmbracoHelper());
|
||||
ctrl.ControllerContext = new ControllerContext(contextBase, routeData, ctrl);
|
||||
|
||||
var result = ctrl.GetContentFromCurrentPage() as PublishedContentResult;
|
||||
@@ -181,6 +183,15 @@ namespace Umbraco.Tests.Web.Mvc
|
||||
|
||||
public class TestSurfaceController : SurfaceController
|
||||
{
|
||||
public TestSurfaceController(UmbracoContext ctx, UmbracoHelper helper = null)
|
||||
: base(ctx, null, new ServiceContext(), Mock.Of<CacheHelper>(), null, null)
|
||||
{
|
||||
if (helper != null)
|
||||
{
|
||||
Umbraco = helper;
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult Index()
|
||||
{
|
||||
return View();
|
||||
|
||||
@@ -8,6 +8,7 @@ using NUnit.Framework;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Composing.LightInject;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
@@ -43,7 +44,7 @@ namespace Umbraco.Tests.Web
|
||||
container.Setup(x => x.GetInstance(typeof(TypeLoader))).Returns(
|
||||
new TypeLoader(NullCacheProvider.Instance, SettingsForTests.GenerateMockGlobalSettings(), new ProfilingLogger(Mock.Of<ILogger>(), Mock.Of<IProfiler>())));
|
||||
container.Setup(x => x.GetInstance(typeof (ServiceContext))).Returns(serviceContext);
|
||||
Current.Container = container.Object;
|
||||
Current.Container = new ContainerAdapter(container.Object);
|
||||
|
||||
Umbraco.Web.Composing.Current.UmbracoContextAccessor = new TestUmbracoContextAccessor();
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using System.Web.Security;
|
||||
using LightInject;
|
||||
using Umbraco.Web.Security;
|
||||
using Umbraco.Web.Security.Providers;
|
||||
|
||||
namespace Umbraco.Web.Composing.CompositionRoots
|
||||
{
|
||||
public class HelperCompositionRoot : ICompositionRoot
|
||||
{
|
||||
public void Compose(IServiceRegistry container)
|
||||
{
|
||||
container.Register((factory) => Core.Security.MembershipProviderExtensions.GetMembersMembershipProvider());
|
||||
container.Register((factory) => Roles.Enabled ? Roles.Provider : new MembersRoleProvider(Core.Composing.Current.Services.MemberService));
|
||||
container.Register<MembershipHelper>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,7 +58,7 @@ namespace Umbraco.Web.Composing
|
||||
/// <summary>
|
||||
/// Gets the DI container.
|
||||
/// </summary>
|
||||
internal static IServiceContainer Container
|
||||
internal static IContainer Container
|
||||
=> CoreCurrent.Container;
|
||||
|
||||
#region Temp & Special
|
||||
|
||||
@@ -2,11 +2,25 @@
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Web.Controllers
|
||||
{
|
||||
public class UmbLoginController : SurfaceController
|
||||
{
|
||||
// fixme - delete?
|
||||
public UmbLoginController()
|
||||
{
|
||||
}
|
||||
|
||||
public UmbLoginController(UmbracoContext umbracoContext, IUmbracoDatabaseFactory databaseFactory, ServiceContext services, CacheHelper applicationCache, ILogger logger, ProfilingLogger profilingLogger)
|
||||
: base(umbracoContext, databaseFactory, services, applicationCache, logger, profilingLogger)
|
||||
{
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult HandleLogin([Bind(Prefix = "loginModel")]LoginModel model)
|
||||
{
|
||||
|
||||
@@ -3,12 +3,25 @@ using System.Web.Security;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Web.Controllers
|
||||
{
|
||||
[MemberAuthorize]
|
||||
public class UmbLoginStatusController : SurfaceController
|
||||
{
|
||||
{
|
||||
// fixme - delete?
|
||||
public UmbLoginStatusController()
|
||||
{
|
||||
}
|
||||
|
||||
public UmbLoginStatusController(UmbracoContext umbracoContext, IUmbracoDatabaseFactory databaseFactory, ServiceContext services, CacheHelper applicationCache, ILogger logger, ProfilingLogger profilingLogger) : base(umbracoContext, databaseFactory, services, applicationCache, logger, profilingLogger)
|
||||
{
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult HandleLogout([Bind(Prefix = "logoutModel")]PostRedirectModel model)
|
||||
{
|
||||
|
||||
@@ -4,12 +4,25 @@ using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Mvc;
|
||||
using Umbraco.Core.Security;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Web.Controllers
|
||||
{
|
||||
[MemberAuthorize]
|
||||
public class UmbProfileController : SurfaceController
|
||||
{
|
||||
// fixme - delete?
|
||||
public UmbProfileController()
|
||||
{
|
||||
}
|
||||
|
||||
public UmbProfileController(UmbracoContext umbracoContext, IUmbracoDatabaseFactory databaseFactory, ServiceContext services, CacheHelper applicationCache, ILogger logger, ProfilingLogger profilingLogger) : base(umbracoContext, databaseFactory, services, applicationCache, logger, profilingLogger)
|
||||
{
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult HandleUpdateProfile([Bind(Prefix = "profileModel")] ProfileModel model)
|
||||
{
|
||||
|
||||
@@ -2,13 +2,26 @@
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Security;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Mvc;
|
||||
|
||||
namespace Umbraco.Web.Controllers
|
||||
{
|
||||
public class UmbRegisterController : SurfaceController
|
||||
{
|
||||
{
|
||||
// fixme - delete?
|
||||
public UmbRegisterController()
|
||||
{
|
||||
}
|
||||
|
||||
public UmbRegisterController(UmbracoContext umbracoContext, IUmbracoDatabaseFactory databaseFactory, ServiceContext services, CacheHelper applicationCache, ILogger logger, ProfilingLogger profilingLogger) : base(umbracoContext, databaseFactory, services, applicationCache, logger, profilingLogger)
|
||||
{
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult HandleRegisterMember([Bind(Prefix = "registerModel")]RegisterModel model)
|
||||
{
|
||||
|
||||
@@ -11,8 +11,8 @@ using System.Web.Mvc;
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNet.Identity;
|
||||
using Microsoft.AspNet.Identity.Owin;
|
||||
using Microsoft.Owin;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Identity;
|
||||
using Umbraco.Core.Security;
|
||||
@@ -26,6 +26,7 @@ using Umbraco.Web.WebApi;
|
||||
using Umbraco.Web.WebApi.Filters;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Web.Composing;
|
||||
using IUser = Umbraco.Core.Models.Membership.IUser;
|
||||
|
||||
@@ -53,6 +54,15 @@ namespace Umbraco.Web.Editors
|
||||
get { return _signInManager ?? (_signInManager = TryGetOwinContext().Result.GetBackOfficeSignInManager()); }
|
||||
}
|
||||
|
||||
public AuthenticationController()
|
||||
{
|
||||
}
|
||||
|
||||
public AuthenticationController(IGlobalSettings globalSettings, UmbracoContext umbracoContext, ISqlContext sqlContext, ServiceContext services, CacheHelper applicationCache, ILogger logger, ProfilingLogger profilingLogger, IRuntimeState runtimeState)
|
||||
: base(globalSettings, umbracoContext, sqlContext, services, applicationCache, logger, profilingLogger, runtimeState)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the configuration for the backoffice user membership provider - used to configure the change password dialog
|
||||
/// </summary>
|
||||
|
||||
@@ -23,6 +23,7 @@ using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Manifest;
|
||||
using Umbraco.Core.Models.Identity;
|
||||
using Umbraco.Core.Models.Membership;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Security;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Mvc;
|
||||
@@ -55,7 +56,13 @@ namespace Umbraco.Web.Editors
|
||||
private const string TokenPasswordResetCode = "PasswordResetCode";
|
||||
private static readonly string[] TempDataTokenNames = { TokenExternalSignInError, TokenPasswordResetCode };
|
||||
|
||||
public BackOfficeController(ManifestParser manifestParser, UmbracoFeatures features)
|
||||
//public BackOfficeController(ManifestParser manifestParser, UmbracoFeatures features)
|
||||
//{
|
||||
// _manifestParser = manifestParser;
|
||||
// _features = features;
|
||||
//}
|
||||
|
||||
public BackOfficeController(ManifestParser manifestParser, UmbracoFeatures features, IGlobalSettings globalSettings, UmbracoContext umbracoContext, IUmbracoDatabaseFactory databaseFactory, ServiceContext services, CacheHelper applicationCache, ILogger logger, ProfilingLogger profilingLogger) : base(globalSettings, umbracoContext, databaseFactory, services, applicationCache, logger, profilingLogger)
|
||||
{
|
||||
_manifestParser = manifestParser;
|
||||
_features = features;
|
||||
|
||||
@@ -3,8 +3,6 @@ using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.Mvc;
|
||||
using System.Linq;
|
||||
using Umbraco.Core.IO;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Net.Http;
|
||||
@@ -16,6 +14,8 @@ using Umbraco.Core.Cache;
|
||||
using Umbraco.Web.WebApi;
|
||||
using Umbraco.Web.WebApi.Filters;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Web.Editors
|
||||
{
|
||||
@@ -27,6 +27,15 @@ namespace Umbraco.Web.Editors
|
||||
[WebApi.UmbracoAuthorize]
|
||||
public class DashboardController : UmbracoApiController
|
||||
{
|
||||
public DashboardController()
|
||||
{
|
||||
}
|
||||
|
||||
public DashboardController(IGlobalSettings globalSettings, UmbracoContext umbracoContext, ISqlContext sqlContext, ServiceContext services, CacheHelper applicationCache, ILogger logger, ProfilingLogger profilingLogger, IRuntimeState runtimeState)
|
||||
: base(globalSettings, umbracoContext, sqlContext, services, applicationCache, logger, profilingLogger, runtimeState)
|
||||
{
|
||||
}
|
||||
|
||||
//we have baseurl as a param to make previewing easier, so we can test with a dev domain from client side
|
||||
[ValidateAngularAntiForgeryToken]
|
||||
public async Task<JObject> GetRemoteDashboardContent(string section, string baseUrl = "https://dashboard.umbraco.org/")
|
||||
|
||||
@@ -5,15 +5,14 @@ using System.Net.Http;
|
||||
using System.Web.Http.Controllers;
|
||||
using System.Web.Http.Filters;
|
||||
using AutoMapper;
|
||||
using LightInject;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.WebApi;
|
||||
|
||||
|
||||
namespace Umbraco.Web.Editors
|
||||
{
|
||||
/// <summary>
|
||||
@@ -21,13 +20,25 @@ namespace Umbraco.Web.Editors
|
||||
/// </summary>
|
||||
internal sealed class DataTypeValidateAttribute : ActionFilterAttribute
|
||||
{
|
||||
// LightInject can inject dependencies into properties
|
||||
public IDataTypeService DataTypeService { get; }
|
||||
|
||||
[Inject]
|
||||
public IDataTypeService DataTypeService { get; set; }
|
||||
public PropertyEditorCollection PropertyEditors { get; }
|
||||
|
||||
[Inject]
|
||||
public PropertyEditorCollection PropertyEditors { get; set; }
|
||||
public DataTypeValidateAttribute()
|
||||
: this(Current.Container.GetInstance<IDataTypeService>(), Current.Container.GetInstance<PropertyEditorCollection>())
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// For use in unit tests. Not possible to use as attribute ctor.
|
||||
/// </summary>
|
||||
/// <param name="dataTypeService"></param>
|
||||
/// <param name="propertyEditors"></param>
|
||||
public DataTypeValidateAttribute(IDataTypeService dataTypeService, PropertyEditorCollection propertyEditors)
|
||||
{
|
||||
DataTypeService = dataTypeService;
|
||||
PropertyEditors = propertyEditors;
|
||||
}
|
||||
|
||||
public override void OnActionExecuting(HttpActionContext actionContext)
|
||||
{
|
||||
|
||||
@@ -3,6 +3,7 @@ using AutoMapper;
|
||||
using Umbraco.Web.Models.ContentEditing;
|
||||
using Umbraco.Web.Mvc;
|
||||
using System.Linq;
|
||||
using LightInject;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Web.Trees;
|
||||
@@ -31,7 +32,7 @@ namespace Umbraco.Web.Editors
|
||||
// since tree's by nature are controllers and require request contextual data - and then we have to
|
||||
// remember to inject properties - nasty indeed
|
||||
var appTreeController = new ApplicationTreeController();
|
||||
Current.Container.InjectProperties(appTreeController);
|
||||
((IServiceContainer)Current.Container.ConcreteContainer).InjectProperties(appTreeController);
|
||||
appTreeController.ControllerContext = ControllerContext;
|
||||
|
||||
var dashboards = dashboardHelper.GetDashboards(Security.CurrentUser);
|
||||
|
||||
@@ -97,7 +97,7 @@ namespace Umbraco.Web
|
||||
}
|
||||
if (cacheByMember)
|
||||
{
|
||||
var helper = new MembershipHelper(Current.UmbracoContext);
|
||||
var helper = Current.Container.GetInstance<MembershipHelper>();
|
||||
var currentMember = helper.GetCurrentMember();
|
||||
cacheKey.AppendFormat("m{0}-", currentMember == null ? 0 : currentMember.Id);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace Umbraco.Web.Models
|
||||
{
|
||||
if (doLookup && Current.UmbracoContext != null)
|
||||
{
|
||||
var helper = new MembershipHelper(Current.UmbracoContext);
|
||||
var helper = Current.Container.GetInstance<MembershipHelper>();
|
||||
var model = helper.GetCurrentLoginStatus();
|
||||
if (model != null)
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Umbraco.Web.Models
|
||||
MemberProperties = new List<UmbracoProperty>();
|
||||
if (doLookup && Current.UmbracoContext != null)
|
||||
{
|
||||
var helper = new MembershipHelper(Current.UmbracoContext);
|
||||
var helper = Current.Container.GetInstance<MembershipHelper>();
|
||||
var model = helper.GetCurrentMemberProfileModel();
|
||||
MemberProperties = model.MemberProperties;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Umbraco.Web.Models
|
||||
CreatePersistentLoginCookie = true;
|
||||
if (doLookup && Current.UmbracoContext != null)
|
||||
{
|
||||
var helper = new MembershipHelper(Current.UmbracoContext);
|
||||
var helper = Current.Container.GetInstance<MembershipHelper>();
|
||||
var model = helper.CreateRegistrationModel(MemberTypeAlias);
|
||||
MemberProperties = model.MemberProperties;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Web.Mvc;
|
||||
using LightInject;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Logging;
|
||||
@@ -36,38 +35,32 @@ namespace Umbraco.Web.Mvc
|
||||
/// <summary>
|
||||
/// Gets or sets the Umbraco context.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public virtual UmbracoContext UmbracoContext { get; set; }
|
||||
public virtual UmbracoContext UmbracoContext { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the database context.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public IUmbracoDatabaseFactory DatabaseFactory { get; set; }
|
||||
public IUmbracoDatabaseFactory DatabaseFactory { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the services context.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public ServiceContext Services { get; set; }
|
||||
public ServiceContext Services { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the application cache.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public CacheHelper ApplicationCache { get; set; }
|
||||
public CacheHelper ApplicationCache { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the logger.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public ILogger Logger { get; set; }
|
||||
public ILogger Logger { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the profiling logger.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public ProfilingLogger ProfilingLogger { get; set; }
|
||||
public ProfilingLogger ProfilingLogger { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the membership helper.
|
||||
@@ -95,6 +88,28 @@ namespace Umbraco.Web.Mvc
|
||||
/// </summary>
|
||||
internal PluginControllerMetadata Metadata => GetMetadata(GetType());
|
||||
|
||||
protected PluginController()
|
||||
: this(
|
||||
Current.Container.GetInstance<UmbracoContext>(),
|
||||
Current.Container.GetInstance<IUmbracoDatabaseFactory>(),
|
||||
Current.Container.GetInstance<ServiceContext>(),
|
||||
Current.Container.GetInstance<CacheHelper>(),
|
||||
Current.Container.GetInstance<ILogger>(),
|
||||
Current.Container.GetInstance<ProfilingLogger>()
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
protected PluginController(UmbracoContext umbracoContext, IUmbracoDatabaseFactory databaseFactory, ServiceContext services, CacheHelper applicationCache, ILogger logger, ProfilingLogger profilingLogger)
|
||||
{
|
||||
UmbracoContext = umbracoContext;
|
||||
DatabaseFactory = databaseFactory;
|
||||
Services = services;
|
||||
ApplicationCache = applicationCache;
|
||||
Logger = logger;
|
||||
ProfilingLogger = profilingLogger;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets metadata for a controller type.
|
||||
/// </summary>
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
using System.Web.Mvc;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.Routing;
|
||||
@@ -18,11 +20,17 @@ namespace Umbraco.Web.Mvc
|
||||
{
|
||||
private PublishedRequest _publishedRequest;
|
||||
|
||||
// fixme - delete?
|
||||
public RenderMvcController()
|
||||
{
|
||||
ActionInvoker = new RenderActionInvoker();
|
||||
}
|
||||
|
||||
public RenderMvcController(IGlobalSettings globalSettings, UmbracoContext umbracoContext, IUmbracoDatabaseFactory databaseFactory, ServiceContext services, CacheHelper applicationCache, ILogger logger, ProfilingLogger profilingLogger) : base(globalSettings, umbracoContext, databaseFactory, services, applicationCache, logger, profilingLogger)
|
||||
{
|
||||
ActionInvoker = new RenderActionInvoker();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Umbraco context.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,7 +1,11 @@
|
||||
using System;
|
||||
using Umbraco.Core;
|
||||
using System.Collections.Specialized;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models.PublishedContent;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Web.Mvc
|
||||
{
|
||||
@@ -12,6 +16,16 @@ namespace Umbraco.Web.Mvc
|
||||
[MergeParentContextViewData]
|
||||
public abstract class SurfaceController : PluginController
|
||||
{
|
||||
// fixme - delete?
|
||||
protected SurfaceController()
|
||||
{
|
||||
}
|
||||
|
||||
protected SurfaceController(UmbracoContext umbracoContext, IUmbracoDatabaseFactory databaseFactory, ServiceContext services, CacheHelper applicationCache, ILogger logger, ProfilingLogger profilingLogger)
|
||||
: base(umbracoContext, databaseFactory, services, applicationCache, logger, profilingLogger)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Redirects to the Umbraco page with the given id
|
||||
/// </summary>
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
namespace Umbraco.Web.Mvc
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Web.Mvc
|
||||
{
|
||||
/// <summary>
|
||||
/// Provides a base class for authorized Umbraco controllers.
|
||||
@@ -10,5 +16,13 @@
|
||||
[UmbracoAuthorize]
|
||||
[DisableBrowserCache]
|
||||
public abstract class UmbracoAuthorizedController : UmbracoController
|
||||
{ }
|
||||
{
|
||||
protected UmbracoAuthorizedController()
|
||||
{
|
||||
}
|
||||
|
||||
protected UmbracoAuthorizedController(IGlobalSettings globalSettings, UmbracoContext umbracoContext, IUmbracoDatabaseFactory databaseFactory, ServiceContext services, CacheHelper applicationCache, ILogger logger, ProfilingLogger profilingLogger) : base(globalSettings, umbracoContext, databaseFactory, services, applicationCache, logger, profilingLogger)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using LightInject;
|
||||
using Microsoft.Owin;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence;
|
||||
@@ -33,43 +32,36 @@ namespace Umbraco.Web.Mvc
|
||||
/// <summary>
|
||||
/// Gets or sets the Umbraco context.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public virtual IGlobalSettings GlobalSettings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Umbraco context.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public virtual UmbracoContext UmbracoContext { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the database context.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public IUmbracoDatabaseFactory DatabaseFactory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the services context.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public ServiceContext Services { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the application cache.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public CacheHelper ApplicationCache { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the logger.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the profiling logger.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public ProfilingLogger ProfilingLogger { get; set; }
|
||||
|
||||
protected IOwinContext OwinContext => Request.GetOwinContext();
|
||||
@@ -89,5 +81,29 @@ namespace Umbraco.Web.Mvc
|
||||
/// Gets the web security helper.
|
||||
/// </summary>
|
||||
public virtual WebSecurity Security => UmbracoContext.Security;
|
||||
|
||||
protected UmbracoController()
|
||||
: this(
|
||||
Current.Container.GetInstance<IGlobalSettings>(),
|
||||
Current.Container.GetInstance<UmbracoContext>(),
|
||||
Current.Container.GetInstance<IUmbracoDatabaseFactory>(),
|
||||
Current.Container.GetInstance<ServiceContext>(),
|
||||
Current.Container.GetInstance<CacheHelper>(),
|
||||
Current.Container.GetInstance<ILogger>(),
|
||||
Current.Container.GetInstance<ProfilingLogger>()
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
protected UmbracoController(IGlobalSettings globalSettings, UmbracoContext umbracoContext, IUmbracoDatabaseFactory databaseFactory, ServiceContext services, CacheHelper applicationCache, ILogger logger, ProfilingLogger profilingLogger)
|
||||
{
|
||||
GlobalSettings = globalSettings;
|
||||
UmbracoContext = umbracoContext;
|
||||
DatabaseFactory = databaseFactory;
|
||||
Services = services;
|
||||
ApplicationCache = applicationCache;
|
||||
Logger = logger;
|
||||
ProfilingLogger = profilingLogger;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.WebPages;
|
||||
using LightInject;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
@@ -34,13 +33,11 @@ namespace Umbraco.Web.Mvc
|
||||
/// <summary>
|
||||
/// Gets or sets the database context.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public ServiceContext Services { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the application cache.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public CacheHelper ApplicationCache { get; set; }
|
||||
|
||||
// fixme
|
||||
@@ -109,6 +106,20 @@ namespace Umbraco.Web.Mvc
|
||||
/// </summary>
|
||||
public MembershipHelper Members => Umbraco.MembershipHelper;
|
||||
|
||||
protected UmbracoViewPage()
|
||||
: this(
|
||||
Current.Container.GetInstance<ServiceContext>(),
|
||||
Current.Container.GetInstance<CacheHelper>()
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
protected UmbracoViewPage(ServiceContext services, CacheHelper applicationCache)
|
||||
{
|
||||
Services = services;
|
||||
ApplicationCache = applicationCache;
|
||||
}
|
||||
|
||||
// view logic below:
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -7,6 +7,7 @@ using System.IO;
|
||||
using System.Web.Security;
|
||||
using umbraco;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
@@ -20,7 +21,7 @@ namespace Umbraco.Web.Routing
|
||||
{
|
||||
// fixme - make this public
|
||||
// fixme - making sense to have an interface?
|
||||
internal class PublishedRouter
|
||||
public class PublishedRouter
|
||||
{
|
||||
private readonly IWebRoutingSection _webRoutingSection;
|
||||
private readonly ContentFinderCollection _contentFinders;
|
||||
@@ -633,7 +634,7 @@ namespace Umbraco.Web.Routing
|
||||
{
|
||||
_logger.Debug<PublishedRouter>(() => $"{tracePrefix}Page is protected, check for access");
|
||||
|
||||
var membershipHelper = new MembershipHelper(request.UmbracoContext);
|
||||
var membershipHelper = Current.Container.GetInstance<MembershipHelper>();
|
||||
|
||||
if (membershipHelper.IsLoggedIn() == false)
|
||||
{
|
||||
|
||||
@@ -56,6 +56,8 @@ namespace Umbraco.Web.Runtime
|
||||
{
|
||||
base.Compose(container);
|
||||
|
||||
container.Register<UmbracoModule>();
|
||||
|
||||
// replace CoreRuntime's IProfiler registration
|
||||
container.RegisterSingleton(_ => _webProfiler);
|
||||
|
||||
|
||||
@@ -70,6 +70,8 @@ namespace Umbraco.Web.Runtime
|
||||
//it still needs to use the install controller so we can't do that
|
||||
composition.Container.RegisterFrom<InstallerCompositionRoot>();
|
||||
|
||||
composition.Container.RegisterFrom<HelperCompositionRoot>();
|
||||
|
||||
// register accessors for cultures
|
||||
composition.Container.RegisterSingleton<IDefaultCultureAccessor, DefaultCultureAccessor>();
|
||||
composition.Container.RegisterSingleton<IVariationContextAccessor, HttpContextVariationContextAccessor>();
|
||||
|
||||
@@ -5,7 +5,6 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Security;
|
||||
using LightInject;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
@@ -34,69 +33,53 @@ namespace Umbraco.Web.Security
|
||||
private readonly IPublishedMemberCache _memberCache;
|
||||
private readonly UmbracoContext _umbracoContext;
|
||||
|
||||
[Inject]
|
||||
private IMemberService MemberService { get; set; }
|
||||
private IMemberService MemberService { get; }
|
||||
|
||||
[Inject]
|
||||
private IMemberTypeService MemberTypeService { get; set; }
|
||||
private IMemberTypeService MemberTypeService { get; }
|
||||
|
||||
[Inject]
|
||||
private IUserService UserService { get; set; }
|
||||
private IUserService UserService { get; }
|
||||
|
||||
[Inject]
|
||||
private IPublicAccessService PublicAccessService { get; set; }
|
||||
private IPublicAccessService PublicAccessService { get; }
|
||||
public CacheHelper CacheHelper { get; }
|
||||
|
||||
[Inject]
|
||||
private CacheHelper ApplicationCache { get; set; }
|
||||
private CacheHelper ApplicationCache { get; }
|
||||
|
||||
[Inject]
|
||||
private ILogger Logger { get; set; }
|
||||
private ILogger Logger { get; }
|
||||
|
||||
[Inject]
|
||||
private PublishedRouter Router { get; set; }
|
||||
private PublishedRouter Router { get; }
|
||||
|
||||
#region Constructors
|
||||
|
||||
// used here and there for IMember operations (not front-end stuff, no need for _memberCache)
|
||||
|
||||
[Obsolete("Use the constructor specifying an UmbracoContext")]
|
||||
[EditorBrowsable(EditorBrowsableState.Never)]
|
||||
public MembershipHelper(HttpContextBase httpContext)
|
||||
public MembershipHelper
|
||||
(
|
||||
IUmbracoContextAccessor accessor,
|
||||
MembershipProvider membershipProvider,
|
||||
RoleProvider roleProvider,
|
||||
IMemberService memberService,
|
||||
IMemberTypeService memberTypeService,
|
||||
IUserService userService,
|
||||
IPublicAccessService publicAccessService,
|
||||
CacheHelper cacheHelper,
|
||||
ILogger logger,
|
||||
PublishedRouter router
|
||||
)
|
||||
{
|
||||
if (httpContext == null) throw new ArgumentNullException(nameof(httpContext));
|
||||
_httpContext = httpContext;
|
||||
_membershipProvider = MPE.GetMembersMembershipProvider();
|
||||
_roleProvider = Roles.Enabled ? Roles.Provider : new MembersRoleProvider(MemberService);
|
||||
|
||||
// _memberCache remains null - not supposed to use it
|
||||
// alternatively we'd need to get if from the 'current' UmbracoContext?
|
||||
|
||||
// helpers are *not* instanciated by the container so we have to
|
||||
// get our dependencies injected manually, through properties.
|
||||
Current.Container.InjectProperties(this);
|
||||
}
|
||||
|
||||
// used everywhere
|
||||
public MembershipHelper(UmbracoContext umbracoContext)
|
||||
: this(umbracoContext, MPE.GetMembersMembershipProvider(), Roles.Enabled ? Roles.Provider : new MembersRoleProvider(Current.Services.MemberService))
|
||||
{ }
|
||||
|
||||
// used in tests and (this)
|
||||
public MembershipHelper(UmbracoContext umbracoContext, MembershipProvider membershipProvider, RoleProvider roleProvider)
|
||||
{
|
||||
if (umbracoContext == null) throw new ArgumentNullException(nameof(umbracoContext));
|
||||
if (accessor.UmbracoContext == null) throw new ArgumentNullException(nameof(accessor));
|
||||
if (membershipProvider == null) throw new ArgumentNullException(nameof(membershipProvider));
|
||||
if (roleProvider == null) throw new ArgumentNullException(nameof(roleProvider));
|
||||
MemberService = memberService;
|
||||
MemberTypeService = memberTypeService;
|
||||
UserService = userService;
|
||||
PublicAccessService = publicAccessService;
|
||||
CacheHelper = cacheHelper;
|
||||
Logger = logger;
|
||||
Router = router;
|
||||
|
||||
_httpContext = umbracoContext.HttpContext;
|
||||
_umbracoContext = umbracoContext;
|
||||
_httpContext = accessor.UmbracoContext.HttpContext;
|
||||
_umbracoContext = accessor.UmbracoContext;
|
||||
_membershipProvider = membershipProvider;
|
||||
_roleProvider = roleProvider;
|
||||
_memberCache = umbracoContext.PublishedSnapshot.Members;
|
||||
|
||||
// helpers are *not* instanciated by the container so we have to
|
||||
// get our dependencies injected manually, through properties.
|
||||
Current.Container.InjectProperties(this);
|
||||
_memberCache = accessor.UmbracoContext.PublishedSnapshot.Members;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace Umbraco.Web.Security
|
||||
{
|
||||
return false;
|
||||
}
|
||||
var helper = new MembershipHelper(Current.UmbracoContext);
|
||||
var helper = Current.Container.GetInstance<MembershipHelper>();
|
||||
return helper.IsMemberAuthorized(allowAll, allowTypes, allowGroups, allowMembers);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ namespace Umbraco.Web.UI.Controls
|
||||
if (umbracoContext == null) throw new ArgumentNullException(nameof(umbracoContext));
|
||||
UmbracoContext = umbracoContext;
|
||||
Umbraco = new UmbracoHelper(umbracoContext, services, appCache);
|
||||
Members = new MembershipHelper(umbracoContext);
|
||||
Members = Current.Container.GetInstance<MembershipHelper>();
|
||||
|
||||
// fixme inject somehow
|
||||
Logger = Current.Logger;
|
||||
|
||||
@@ -109,6 +109,7 @@
|
||||
<Compile Include="Cache\ContentCacheRefresher.cs" />
|
||||
<Compile Include="Cache\UserGroupCacheRefresher.cs" />
|
||||
<Compile Include="Cache\UserGroupPermissionsCacheRefresher.cs" />
|
||||
<Compile Include="Composing\CompositionRoots\HelperCompositionRoot.cs" />
|
||||
<Compile Include="Composing\CompositionRoots\InstallerCompositionRoot.cs" />
|
||||
<Compile Include="CompositionExtensions.cs" />
|
||||
<Compile Include="Composing\Current.cs" />
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace Umbraco.Web
|
||||
/// Gets the membership helper.
|
||||
/// </summary>
|
||||
public MembershipHelper MembershipHelper => _membershipHelper
|
||||
?? (_membershipHelper = new MembershipHelper(UmbracoContext));
|
||||
?? (_membershipHelper = Current.Container.GetInstance<MembershipHelper>());
|
||||
|
||||
/// <summary>
|
||||
/// Gets the url provider.
|
||||
|
||||
@@ -4,8 +4,10 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using LightInject;
|
||||
using Microsoft.Web.Infrastructure.DynamicModuleHelper;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.IO;
|
||||
@@ -22,8 +24,38 @@ using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Composing;
|
||||
using Umbraco.Web.PublishedCache;
|
||||
|
||||
[assembly: PreApplicationStartMethod(typeof(Umbraco.Web.ContainerUmbracoModule), "Start")]
|
||||
namespace Umbraco.Web
|
||||
{
|
||||
public class ContainerUmbracoModule : IHttpModule
|
||||
{
|
||||
private UmbracoModule umbracoModule;
|
||||
|
||||
public static void Start()
|
||||
{
|
||||
DynamicModuleUtility.RegisterModule(typeof(ContainerUmbracoModule));
|
||||
}
|
||||
|
||||
public ContainerUmbracoModule()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void Init(HttpApplication context)
|
||||
{
|
||||
// Should be extended with lazy list of modules from registry
|
||||
// Example here: https://haacked.com/archive/2011/06/03/dependency-injection-with-asp-net-httpmodules.aspx/
|
||||
|
||||
umbracoModule = Current.Container.GetInstance<UmbracoModule>();
|
||||
umbracoModule.Init(context);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
umbracoModule.Dispose();
|
||||
}
|
||||
}
|
||||
|
||||
// also look at IOHelper.ResolveUrlsFromTextString - nightmarish?!
|
||||
|
||||
// context.RewritePath supports ~/ or else must begin with /vdir
|
||||
@@ -38,44 +70,57 @@ namespace Umbraco.Web
|
||||
// get our dependencies injected manually, through properties, in
|
||||
// Init(). works for dependencies that are singletons.
|
||||
|
||||
[Inject]
|
||||
public IUmbracoSettingsSection UmbracoSettings { get; set; }
|
||||
|
||||
[Inject]
|
||||
public IGlobalSettings GlobalSettings { get; set; }
|
||||
|
||||
[Inject]
|
||||
public IUmbracoContextAccessor UmbracoContextAccessor { get; set; }
|
||||
|
||||
[Inject]
|
||||
public IPublishedSnapshotService PublishedSnapshotService { get; set; }
|
||||
|
||||
[Inject]
|
||||
public IUserService UserService { get; set; }
|
||||
|
||||
[Inject]
|
||||
public UrlProviderCollection UrlProviders { get; set; }
|
||||
|
||||
[Inject]
|
||||
public IRuntimeState Runtime { get; set; }
|
||||
|
||||
[Inject]
|
||||
public ILogger Logger { get; set; }
|
||||
|
||||
[Inject]
|
||||
internal PublishedRouter PublishedRouter { get; set; }
|
||||
|
||||
[Inject]
|
||||
internal IUmbracoDatabaseFactory DatabaseFactory { get; set; }
|
||||
|
||||
[Inject]
|
||||
internal IVariationContextAccessor VariationContextAccessor { get; set; }
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
public UmbracoModule()
|
||||
|
||||
public UmbracoModule(
|
||||
IUmbracoSettingsSection umbracoSettings,
|
||||
IGlobalSettings globalSettings,
|
||||
IUmbracoContextAccessor umbracoContextAccessor,
|
||||
IPublishedSnapshotService publishedSnapshotService,
|
||||
IUserService userService,
|
||||
UrlProviderCollection urlProviders,
|
||||
IRuntimeState runtime,
|
||||
ILogger logger,
|
||||
PublishedRouter publishedRouter,
|
||||
IUmbracoDatabaseFactory databaseFactory,
|
||||
IVariationContextAccessor variationContextAccessor
|
||||
)
|
||||
{
|
||||
_combinedRouteCollection = new Lazy<RouteCollection>(CreateRouteCollection);
|
||||
|
||||
UmbracoSettings = umbracoSettings;
|
||||
GlobalSettings = globalSettings;
|
||||
UmbracoContextAccessor = umbracoContextAccessor;
|
||||
PublishedSnapshotService = publishedSnapshotService;
|
||||
UserService = userService;
|
||||
UrlProviders = urlProviders;
|
||||
Runtime = runtime;
|
||||
Logger = logger;
|
||||
PublishedRouter = publishedRouter;
|
||||
DatabaseFactory = databaseFactory;
|
||||
VariationContextAccessor = variationContextAccessor;
|
||||
}
|
||||
|
||||
#region HttpModule event handlers
|
||||
@@ -543,10 +588,10 @@ namespace Umbraco.Web
|
||||
};
|
||||
return;
|
||||
}
|
||||
|
||||
// modules are *not* instanciated by the container so we have to
|
||||
|
||||
// modules **are** instanciated by the container so we **don't** have to
|
||||
// get our dependencies injected manually, through properties.
|
||||
Core.Composing.Current.Container.InjectProperties(this);
|
||||
//Core.Composing.Current.Container.InjectProperties(this);
|
||||
|
||||
app.BeginRequest += (sender, e) =>
|
||||
{
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Web.WebApi
|
||||
{
|
||||
@@ -6,5 +12,14 @@ namespace Umbraco.Web.WebApi
|
||||
/// Provides a base class for auto-routed Umbraco API controllers.
|
||||
/// </summary>
|
||||
public abstract class UmbracoApiController : UmbracoApiControllerBase, IDiscoverable
|
||||
{ }
|
||||
{
|
||||
protected UmbracoApiController()
|
||||
{
|
||||
}
|
||||
|
||||
protected UmbracoApiController(IGlobalSettings globalSettings, UmbracoContext umbracoContext, ISqlContext sqlContext, ServiceContext services, CacheHelper applicationCache, ILogger logger, ProfilingLogger profilingLogger, IRuntimeState runtimeState)
|
||||
: base(globalSettings, umbracoContext, sqlContext, services, applicationCache, logger, profilingLogger, runtimeState)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Web.Http;
|
||||
using LightInject;
|
||||
using Microsoft.Owin;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Composing;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence;
|
||||
@@ -36,50 +36,42 @@ namespace Umbraco.Web.WebApi
|
||||
/// <summary>
|
||||
/// Gets or sets the Umbraco context.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public virtual IGlobalSettings GlobalSettings { get; set; }
|
||||
public virtual IGlobalSettings GlobalSettings { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the Umbraco context.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public virtual UmbracoContext UmbracoContext { get; set; }
|
||||
public virtual UmbracoContext UmbracoContext { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the sql context.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public ISqlContext SqlContext { get; set; }
|
||||
public ISqlContext SqlContext { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the services context.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public ServiceContext Services { get; set; }
|
||||
public ServiceContext Services { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the application cache.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public CacheHelper ApplicationCache { get; set; }
|
||||
public CacheHelper ApplicationCache { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the logger.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public ILogger Logger { get; set; }
|
||||
public ILogger Logger { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the profiling logger.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
public ProfilingLogger ProfilingLogger { get; set; }
|
||||
public ProfilingLogger ProfilingLogger { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the runtime state.
|
||||
/// </summary>
|
||||
[Inject]
|
||||
internal IRuntimeState RuntimeState { get; set; }
|
||||
internal IRuntimeState RuntimeState { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the application url.
|
||||
@@ -102,6 +94,33 @@ namespace Umbraco.Web.WebApi
|
||||
/// </summary>
|
||||
public WebSecurity Security => UmbracoContext.Security;
|
||||
|
||||
protected UmbracoApiControllerBase()
|
||||
: this(
|
||||
Current.Container.GetInstance<IGlobalSettings>(),
|
||||
Current.Container.GetInstance<UmbracoContext>(),
|
||||
Current.Container.GetInstance<ISqlContext>(),
|
||||
Current.Container.GetInstance<ServiceContext>(),
|
||||
Current.Container.GetInstance<CacheHelper>(),
|
||||
Current.Container.GetInstance<ILogger>(),
|
||||
Current.Container.GetInstance<ProfilingLogger>(),
|
||||
Current.Container.GetInstance<IRuntimeState>()
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
// fixme - Inject fewer things? (Aggregate more)
|
||||
protected UmbracoApiControllerBase(IGlobalSettings globalSettings, UmbracoContext umbracoContext, ISqlContext sqlContext, ServiceContext services, CacheHelper applicationCache, ILogger logger, ProfilingLogger profilingLogger, IRuntimeState runtimeState)
|
||||
{
|
||||
GlobalSettings = globalSettings;
|
||||
UmbracoContext = umbracoContext;
|
||||
SqlContext = sqlContext;
|
||||
Services = services;
|
||||
ApplicationCache = applicationCache;
|
||||
Logger = logger;
|
||||
ProfilingLogger = profilingLogger;
|
||||
RuntimeState = runtimeState;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to get the current HttpContext.
|
||||
/// </summary>
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
using Umbraco.Web.WebApi.Filters;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Web.WebApi.Filters;
|
||||
using Umbraco.Core.Models.Identity;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Security;
|
||||
using Umbraco.Core.Services;
|
||||
|
||||
namespace Umbraco.Web.WebApi
|
||||
{
|
||||
@@ -25,5 +31,14 @@ namespace Umbraco.Web.WebApi
|
||||
|
||||
protected BackOfficeUserManager<BackOfficeIdentityUser> UserManager
|
||||
=> _userManager ?? (_userManager = TryGetOwinContext().Result.GetBackOfficeUserManager());
|
||||
|
||||
protected UmbracoAuthorizedApiController()
|
||||
{
|
||||
}
|
||||
|
||||
protected UmbracoAuthorizedApiController(IGlobalSettings globalSettings, UmbracoContext umbracoContext, ISqlContext sqlContext, ServiceContext services, CacheHelper applicationCache, ILogger logger, ProfilingLogger profilingLogger, IRuntimeState runtimeState)
|
||||
: base(globalSettings, umbracoContext, sqlContext, services, applicationCache, logger, profilingLogger, runtimeState)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,10 @@
|
||||
using System.Collections.Generic;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Configuration;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Web.Models;
|
||||
using Umbraco.Web.WebApi;
|
||||
|
||||
@@ -13,6 +19,15 @@ namespace Umbraco.Web.WebServices
|
||||
/// </remarks>
|
||||
public class TagsController : UmbracoApiController
|
||||
{
|
||||
public TagsController()
|
||||
{
|
||||
}
|
||||
|
||||
public TagsController(IGlobalSettings globalSettings, UmbracoContext umbracoContext, ISqlContext sqlContext, ServiceContext services, CacheHelper applicationCache, ILogger logger, ProfilingLogger profilingLogger, IRuntimeState runtimeState)
|
||||
: base(globalSettings, umbracoContext, sqlContext, services, applicationCache, logger, profilingLogger, runtimeState)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get every tag stored in the database (with optional group)
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user