Refactor collection builders for IContainer

This commit is contained in:
Stephan
2018-07-20 16:36:46 +02:00
parent 5836cd05cb
commit 97da0829a2
45 changed files with 175 additions and 142 deletions
@@ -1,12 +1,10 @@
using System.Collections.Generic;
using LightInject;
using Umbraco.Core.Composing;
using Umbraco.Core.Composing;
namespace Umbraco.Core.Cache
{
public class CacheRefresherCollectionBuilder : LazyCollectionBuilderBase<CacheRefresherCollectionBuilder, CacheRefresherCollection, ICacheRefresher>
{
public CacheRefresherCollectionBuilder(IServiceContainer container)
public CacheRefresherCollectionBuilder(IContainer container)
: base(container)
{ }
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using LightInject;
namespace Umbraco.Core.Composing
{
@@ -19,14 +18,14 @@ namespace Umbraco.Core.Composing
private readonly List<Type> _types = new List<Type>();
private readonly object _locker = new object();
private Func<IEnumerable<TItem>, TCollection> _collectionCtor;
private ServiceRegistration[] _registrations;
private Registration[] _registrations;
/// <summary>
/// Initializes a new instance of the <see cref="CollectionBuilderBase{TBuilder, TCollection,TItem}"/>
/// class with a service container.
/// </summary>
/// <param name="container">A service container.</param>
protected CollectionBuilderBase(IServiceContainer container)
/// <param name="container">A container.</param>
protected CollectionBuilderBase(IContainer container)
{
Container = container;
// ReSharper disable once DoNotCallOverridableMethodsInConstructor
@@ -34,9 +33,9 @@ namespace Umbraco.Core.Composing
}
/// <summary>
/// Gets the service container.
/// Gets the container.
/// </summary>
protected IServiceContainer Container { get; }
protected IContainer Container { get; }
/// <summary>
/// Gets the internal list of types as an IEnumerable (immutable).
@@ -64,7 +63,7 @@ namespace Umbraco.Core.Composing
// else _collectionCtor remains null, assuming CreateCollection has been overriden
// we just don't want to support re-registering collections here
var registration = Container.GetAvailableService<TCollection>();
var registration = Container.GetRegistered<TCollection>().FirstOrDefault();
if (registration != null)
throw new InvalidOperationException("Collection builders cannot be registered once the collection itself has been registered.");
@@ -75,8 +74,7 @@ namespace Umbraco.Core.Composing
/// <summary>
/// Gets the collection lifetime.
/// </summary>
/// <remarks>Return null for transient collections.</remarks>
protected virtual ILifetime CollectionLifetime => new PerContainerLifetime();
protected virtual Lifetime CollectionLifetime => Lifetime.Singleton;
/// <summary>
/// Configures the internal list of types.
@@ -122,7 +120,11 @@ namespace Umbraco.Core.Composing
Container.Register(typeof(TItem), type, name);
}
_registrations = Container.AvailableServices
// note: we do this, because we don't want to get "all",
// because other types implementing TItem may be registered,
// and we only want those for *this* builder
_registrations = Container.GetRegistered(typeof(TItem))
.Where(x => x.ServiceName.StartsWith(prefix))
.OrderBy(x => x.ServiceName)
.ToArray();
@@ -134,13 +136,13 @@ namespace Umbraco.Core.Composing
/// </summary>
/// <param name="args">The arguments.</param>
/// <returns>The collection items.</returns>
protected virtual IEnumerable<TItem> CreateItems(params object[] args)
protected virtual IEnumerable<TItem> CreateItems(/*params object[] args*/)
{
RegisterTypes(); // will do it only once
var type = typeof (TItem);
return _registrations
.Select(x => (TItem) Container.GetInstance(type, x.ServiceName, args))
.Select(x => (TItem) Container.GetInstance(type, x.ServiceName/*, args*/))
.ToArray(); // safe
}
+11 -3
View File
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Reflection;
namespace Umbraco.Core.Composing
{
@@ -66,6 +67,9 @@ namespace Umbraco.Core.Composing
/// <typeparam name="TService">The type of the service.</typeparam>
IEnumerable<TService> GetAllInstances<TService>();
// fixme
IEnumerable<Registration> GetRegistered(Type serviceType);
#endregion
#region Registry
@@ -117,6 +121,10 @@ namespace Umbraco.Core.Composing
/// <returns>A collection builder of the specified type.</returns>
T RegisterCollectionBuilder<T>();
// fixme - very LightInject specific? or?
void RegisterConstructorDependency<TDependency>(Func<IContainer, ParameterInfo, TDependency> factory);
void RegisterConstructorDependency<TDependency>(Func<IContainer, ParameterInfo, object[], TDependency> factory);
#endregion
#region Control
@@ -132,11 +140,11 @@ namespace Umbraco.Core.Composing
// fixme - document all these
void ConfigureForUmbraco();
IContainer ConfigureForUmbraco();
void ConfigureForWeb();
IContainer ConfigureForWeb();
void EnablePerWebRequestScope();
IContainer EnablePerWebRequestScope();
#endregion
}
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using LightInject;
namespace Umbraco.Core.Composing
{
@@ -16,13 +15,13 @@ namespace Umbraco.Core.Composing
where TCollection : IBuilderCollection<TItem>
{
private readonly List<Func<IEnumerable<Type>>> _producers1 = new List<Func<IEnumerable<Type>>>();
private readonly List<Func<IServiceFactory, IEnumerable<Type>>> _producers2 = new List<Func<IServiceFactory, IEnumerable<Type>>>();
private readonly List<Func<IContainer, IEnumerable<Type>>> _producers2 = new List<Func<IContainer, IEnumerable<Type>>>();
private readonly List<Type> _excluded = new List<Type>();
/// <summary>
/// Initializes a new instance of the <see cref="LazyCollectionBuilderBase{TBuilder,TCollection,TItem}"/> class.
/// </summary>
protected LazyCollectionBuilderBase(IServiceContainer container)
protected LazyCollectionBuilderBase(IContainer container)
: base(container)
{ }
@@ -125,7 +124,7 @@ namespace Umbraco.Core.Composing
/// </summary>
/// <param name="producer">The types producer.</param>
/// <returns>The builder.</returns>
public TBuilder Add(Func<IServiceFactory, IEnumerable<Type>> producer)
public TBuilder Add(Func<IContainer, IEnumerable<Type>> producer)
{
Configure(types =>
{
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using LightInject;
namespace Umbraco.Core.Composing.LightInject
@@ -56,6 +57,10 @@ namespace Umbraco.Core.Composing.LightInject
public IEnumerable<object> GetAllInstances(Type type)
=> Container.GetAllInstances(type);
/// <inheritdoc />
public IEnumerable<Registration> GetRegistered(Type type)
=> Container.GetAvailableServices(type).Select(x => new Registration(x.ServiceType, x.ServiceName));
#endregion
#region Registry
@@ -173,6 +178,14 @@ namespace Umbraco.Core.Composing.LightInject
public void RegisterOrdered(Type serviceType, Type[] implementingTypes, Lifetime lifetime = Lifetime.Transient)
=> Container.RegisterOrdered(serviceType, implementingTypes, _ => GetLifetime(lifetime));
/// <inheritdoc />
public void RegisterConstructorDependency<TDependency>(Func<IContainer, ParameterInfo, TDependency> factory)
=> Container.RegisterConstructorDependency((f, x) => factory(this, x));
/// <inheritdoc />
public void RegisterConstructorDependency<TDependency>(Func<IContainer, ParameterInfo, object[], TDependency> factory)
=> Container.RegisterConstructorDependency((f, x, a) => factory(this, x, a));
/// <inheritdoc />
public T RegisterCollectionBuilder<T>()
=> Container.RegisterCollectionBuilder<T>();
@@ -186,7 +199,7 @@ namespace Umbraco.Core.Composing.LightInject
=> Container.BeginScope();
/// <inheritdoc />
public void ConfigureForUmbraco()
public IContainer ConfigureForUmbraco()
{
// supports annotated constructor injections
// eg to specify the service name on some services
@@ -211,6 +224,8 @@ namespace Umbraco.Core.Composing.LightInject
// see notes in MixedLightInjectScopeManagerProvider
Container.ScopeManagerProvider = new MixedLightInjectScopeManagerProvider();
return this;
}
private class AssemblyScanner : IAssemblyScanner
@@ -234,15 +249,18 @@ namespace Umbraco.Core.Composing.LightInject
}
/// <inheritdoc />
public virtual void ConfigureForWeb()
{ }
public virtual IContainer ConfigureForWeb()
{
return this;
}
/// <inheritdoc />
public void EnablePerWebRequestScope()
public IContainer EnablePerWebRequestScope()
{
if (!(Container.ScopeManagerProvider is MixedLightInjectScopeManagerProvider smp))
throw new Exception("Container.ScopeManagerProvider is not MixedLightInjectScopeManagerProvider.");
smp.EnablePerWebRequestScope();
return this;
}
#endregion
@@ -1,7 +1,7 @@
using LightInject;
using LightInject.Web;
namespace Umbraco.Core.Composing
namespace Umbraco.Core.Composing.LightInject
{
// by default, the container's scope manager provider is PerThreadScopeManagerProvider,
// and then container.EnablePerWebRequestScope() replaces it with PerWebRequestScopeManagerProvider,
@@ -134,7 +134,7 @@ namespace Umbraco.Core.Composing
/// <summary>
/// Updates a registration.
/// </summary>
private static void UpdateRegistration(Registration registration, Type implementingType, Delegate factoryExpression)
private static void UpdateRegistration(ServiceRegistration registration, Type implementingType, Delegate factoryExpression)
{
// if the container has compiled already then the registrations have been captured,
// and re-registering - although updating available services - does not modify the
@@ -1,6 +1,5 @@
using System;
using System.Collections.Generic;
using LightInject;
namespace Umbraco.Core.Composing
{
@@ -18,7 +17,7 @@ namespace Umbraco.Core.Composing
/// Initializes a new instance of the <see cref="OrderedCollectionBuilderBase{TBuilder,TCollection,TItem}"/> class.
/// </summary>
/// <param name="container"></param>
protected OrderedCollectionBuilderBase(IServiceContainer container)
protected OrderedCollectionBuilderBase(IContainer container)
: base (container)
{ }
@@ -92,7 +91,7 @@ namespace Umbraco.Core.Composing
/// </summary>
/// <param name="types">The types to append.</param>
/// <returns>The builder.</returns>
public TBuilder Append(Func<IServiceFactory, IEnumerable<Type>> types)
public TBuilder Append(Func<IContainer, IEnumerable<Type>> types)
{
Configure(list =>
{
@@ -0,0 +1,31 @@
using System;
namespace Umbraco.Core.Composing
{
/// <summary>
/// Represents a service registration in the container.
/// </summary>
public class Registration
{
/// <summary>
/// Initializes a new instance of the <see cref="Registration"/> class.
/// </summary>
/// <param name="serviceType"></param>
/// <param name="serviceName"></param>
public Registration(Type serviceType, string serviceName)
{
ServiceType = serviceType;
ServiceName = serviceName;
}
/// <summary>
/// Gets the service type.
/// </summary>
public Type ServiceType { get; }
/// <summary>
/// Gets the service name.
/// </summary>
public string ServiceName { get; }
}
}
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using LightInject;
namespace Umbraco.Core.Composing
{
@@ -19,7 +18,7 @@ namespace Umbraco.Core.Composing
/// Initializes a new instance of the <see cref="WeightedCollectionBuilderBase{TBuilder,TCollection,TItem}"/> class.
/// </summary>
/// <param name="container"></param>
protected WeightedCollectionBuilderBase(IServiceContainer container)
protected WeightedCollectionBuilderBase(IContainer container)
: base(container)
{ }
+4
View File
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Umbraco.Core.Composing;
namespace Umbraco.Core
@@ -45,6 +46,9 @@ namespace Umbraco.Core
// fixme - document all these
public static IEnumerable<Registration> GetRegistered<TService>(this IContainer container)
=> container.GetRegistered(typeof(TService));
public static void Register<TService, TImplementing>(this IContainer container, Lifetime lifetime = Lifetime.Transient)
=> container.Register(typeof(TService), typeof(TImplementing), lifetime);
@@ -1,5 +1,4 @@
using System;
using LightInject;
using Umbraco.Core.Composing;
namespace Umbraco.Core.Migrations
@@ -1,16 +1,15 @@
using LightInject;
using Umbraco.Core.Composing;
using Umbraco.Core.Composing;
namespace Umbraco.Core.Migrations
{
public class PostMigrationCollectionBuilder : LazyCollectionBuilderBase<PostMigrationCollectionBuilder, PostMigrationCollection, IPostMigration>
{
public PostMigrationCollectionBuilder(IServiceContainer container)
public PostMigrationCollectionBuilder(IContainer container)
: base(container)
{ }
protected override PostMigrationCollectionBuilder This => this;
protected override ILifetime CollectionLifetime => null; // transient
protected override Lifetime CollectionLifetime => Lifetime.Transient;
}
}
@@ -1,11 +1,10 @@
using LightInject;
using Umbraco.Core.Composing;
using Umbraco.Core.Composing;
namespace Umbraco.Core.Persistence.Mappers
{
public class MapperCollectionBuilder : LazyCollectionBuilderBase<MapperCollectionBuilder, MapperCollection, BaseMapper>
{
public MapperCollectionBuilder(IServiceContainer container)
public MapperCollectionBuilder(IContainer container)
: base(container)
{ }
@@ -1,11 +1,10 @@
using LightInject;
using Umbraco.Core.Composing;
using Umbraco.Core.Composing;
namespace Umbraco.Core.PropertyEditors
{
public class DataEditorCollectionBuilder : LazyCollectionBuilderBase<DataEditorCollectionBuilder, DataEditorCollection, IDataEditor>
{
public DataEditorCollectionBuilder(IServiceContainer container)
public DataEditorCollectionBuilder(IContainer container)
: base(container)
{ }
@@ -1,11 +1,10 @@
using LightInject;
using Umbraco.Core.Composing;
using Umbraco.Core.Composing;
namespace Umbraco.Core.PropertyEditors
{
internal class ManifestValueValidatorCollectionBuilder : LazyCollectionBuilderBase<ManifestValueValidatorCollectionBuilder, ManifestValueValidatorCollection, IManifestValueValidator>
{
public ManifestValueValidatorCollectionBuilder(IServiceContainer container)
public ManifestValueValidatorCollectionBuilder(IContainer container)
: base(container)
{ }
@@ -1,11 +1,10 @@
using LightInject;
using Umbraco.Core.Composing;
using Umbraco.Core.Composing;
namespace Umbraco.Core.PropertyEditors
{
public class PropertyValueConverterCollectionBuilder : OrderedCollectionBuilderBase<PropertyValueConverterCollectionBuilder, PropertyValueConverterCollection, IPropertyValueConverter>
{
public PropertyValueConverterCollectionBuilder(IServiceContainer container)
public PropertyValueConverterCollectionBuilder(IContainer container)
: base(container)
{ }
@@ -1,11 +1,10 @@
using LightInject;
using Umbraco.Core.Composing;
using Umbraco.Core.Composing;
namespace Umbraco.Core.Strings
{
public class UrlSegmentProviderCollectionBuilder : OrderedCollectionBuilderBase<UrlSegmentProviderCollectionBuilder, UrlSegmentProviderCollection, IUrlSegmentProvider>
{
public UrlSegmentProviderCollectionBuilder(IServiceContainer container)
public UrlSegmentProviderCollectionBuilder(IContainer container)
: base(container)
{ }
+2 -1
View File
@@ -170,8 +170,9 @@
<Compile Include="Composing\Lifetime.cs" />
<Compile Include="Composing\LightInjectExtensions.cs" />
<Compile Include="Composing\LightInject\LightInjectContainer.cs" />
<Compile Include="Composing\MixedLightInjectScopeManagerProvider.cs" />
<Compile Include="Composing\LightInject\MixedLightInjectScopeManagerProvider.cs" />
<Compile Include="Composing\OrderedCollectionBuilderBase.cs" />
<Compile Include="Composing\Registration.cs" />
<Compile Include="Composing\TypeFinder.cs" />
<Compile Include="Composing\TypeHelper.cs" />
<Compile Include="Composing\TypeLoader.cs" />
@@ -1,11 +1,10 @@
using LightInject;
using Umbraco.Core.Composing;
using Umbraco.Core.Composing;
namespace Umbraco.Core._Legacy.PackageActions
{
internal class PackageActionCollectionBuilder : LazyCollectionBuilderBase<PackageActionCollectionBuilder, PackageActionCollection, IPackageAction>
{
public PackageActionCollectionBuilder(IServiceContainer container)
public PackageActionCollectionBuilder(IContainer container)
: base(container)
{ }
@@ -435,7 +435,7 @@ namespace Umbraco.Tests.Composing
// ReSharper disable once ClassNeverInstantiated.Local
private class TestCollectionBuilder : OrderedCollectionBuilderBase<TestCollectionBuilder, TestCollection, Resolved>
{
public TestCollectionBuilder(IServiceContainer container)
public TestCollectionBuilder(IContainer container)
: base(container)
{ }
@@ -445,31 +445,31 @@ namespace Umbraco.Tests.Composing
// ReSharper disable once ClassNeverInstantiated.Local
private class TestCollectionBuilderTransient : OrderedCollectionBuilderBase<TestCollectionBuilderTransient, TestCollection, Resolved>
{
public TestCollectionBuilderTransient(IServiceContainer container)
public TestCollectionBuilderTransient(IContainer container)
: base(container)
{ }
protected override TestCollectionBuilderTransient This => this;
protected override ILifetime CollectionLifetime => null; // transient
protected override Lifetime CollectionLifetime => Lifetime.Transient; // transient
}
// ReSharper disable once ClassNeverInstantiated.Local
private class TestCollectionBuilderScope : OrderedCollectionBuilderBase<TestCollectionBuilderScope, TestCollection, Resolved>
{
public TestCollectionBuilderScope(IServiceContainer container)
public TestCollectionBuilderScope(IContainer container)
: base(container)
{ }
protected override TestCollectionBuilderScope This => this;
protected override ILifetime CollectionLifetime => new PerScopeLifetime();
protected override Lifetime CollectionLifetime => Lifetime.Scope;
}
// ReSharper disable once ClassNeverInstantiated.Local
private class TestCollectionBuilderWeighted : WeightedCollectionBuilderBase<TestCollectionBuilderWeighted, TestCollection, Resolved>
{
public TestCollectionBuilderWeighted(IServiceContainer container)
public TestCollectionBuilderWeighted(IContainer container)
: base(container)
{ }
@@ -1,11 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using LightInject;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Composing.LightInject;
namespace Umbraco.Tests.Composing
{
@@ -24,6 +22,9 @@ namespace Umbraco.Tests.Composing
Current.Reset();
}
private IContainer CreateContainer()
=> Current.Container = (new Core.Composing.LightInject.LightInjectContainer(new LightInject.ServiceContainer())).ConfigureForUmbraco();
// note
// lazy collection builder does not throw on duplicate, just uses distinct types
// so we don't have a test for duplicates as we had with resolvers in v7
@@ -31,9 +32,7 @@ namespace Umbraco.Tests.Composing
[Test]
public void LazyCollectionBuilderHandlesTypes()
{
var container = new ServiceContainer();
container.ConfigureUmbracoCore();
Current.Container = new LightInjectContainer(container);
var container = CreateContainer();
container.RegisterCollectionBuilder<TestCollectionBuilder>()
.Add<TransientObject3>()
@@ -56,9 +55,7 @@ namespace Umbraco.Tests.Composing
[Test]
public void LazyCollectionBuilderHandlesProducers()
{
var container = new ServiceContainer();
container.ConfigureUmbracoCore();
Current.Container = new LightInjectContainer(container);
var container = CreateContainer();
container.RegisterCollectionBuilder<TestCollectionBuilder>()
.Add(() => new[] { typeof(TransientObject3), typeof(TransientObject2) })
@@ -80,9 +77,7 @@ namespace Umbraco.Tests.Composing
[Test]
public void LazyCollectionBuilderHandlesTypesAndProducers()
{
var container = new ServiceContainer();
container.ConfigureUmbracoCore();
Current.Container = new LightInjectContainer(container);
var container = CreateContainer();
container.RegisterCollectionBuilder<TestCollectionBuilder>()
.Add<TransientObject3>()
@@ -105,9 +100,7 @@ namespace Umbraco.Tests.Composing
[Test]
public void LazyCollectionBuilderThrowsOnIllegalTypes()
{
var container = new ServiceContainer();
container.ConfigureUmbracoCore();
Current.Container = new LightInjectContainer(container);
var container = CreateContainer();
container.RegisterCollectionBuilder<TestCollectionBuilder>()
.Add<TransientObject3>()
@@ -128,9 +121,7 @@ namespace Umbraco.Tests.Composing
[Test]
public void LazyCollectionBuilderCanExcludeTypes()
{
var container = new ServiceContainer();
container.ConfigureUmbracoCore();
Current.Container = new LightInjectContainer(container);
var container = CreateContainer();
container.RegisterCollectionBuilder<TestCollectionBuilder>()
.Add<TransientObject3>()
@@ -171,13 +162,13 @@ namespace Umbraco.Tests.Composing
// ReSharper disable once ClassNeverInstantiated.Local
private class TestCollectionBuilder : LazyCollectionBuilderBase<TestCollectionBuilder, TestCollection, ITestInterface>
{
public TestCollectionBuilder(IServiceContainer container)
public TestCollectionBuilder(IContainer container)
: base(container)
{ }
protected override TestCollectionBuilder This => this;
protected override ILifetime CollectionLifetime => null; // transient
protected override Lifetime CollectionLifetime => Lifetime.Transient; // transient
}
// ReSharper disable once ClassNeverInstantiated.Local
@@ -54,7 +54,7 @@ namespace Umbraco.Tests.Integration
base.Compose();
Container.Register<IServerRegistrar>(_ => new TestServerRegistrar()); // localhost-only
Container.Register<IServerMessenger, LocalServerMessenger>(new PerContainerLifetime());
Container.RegisterSingleton<IServerMessenger, LocalServerMessenger>();
Container.RegisterCollectionBuilder<CacheRefresherCollectionBuilder>()
.Add<ContentTypeCacheRefresher>()
+1 -1
View File
@@ -3,7 +3,7 @@ using NUnit.Framework;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence;
using Umbraco.Tests.Testing;
using LightInject;
using Umbraco.Core;
using Umbraco.Tests.TestHelpers;
namespace Umbraco.Tests.Issues
+1 -1
View File
@@ -6,7 +6,7 @@ using System.IO;
using System.Linq;
using System.Web;
using Moq;
using LightInject;
using Umbraco.Core;
using NUnit.Framework;
using Umbraco.Core.Cache;
using Umbraco.Core.Configuration.UmbracoSettings;
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using AutoMapper;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Cache;
using Umbraco.Core.Manifest;
using Umbraco.Core.PropertyEditors;
@@ -6,8 +6,7 @@ using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Repositories;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.Testing;
using LightInject;
using Umbraco.Core.Scoping;
using Umbraco.Core;
namespace Umbraco.Tests.Persistence.Repositories
{
@@ -1,13 +1,11 @@
using System.Linq;
using Moq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.IO;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Repositories;
using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Composing;
using Umbraco.Core.Persistence.Repositories.Implement;
using Umbraco.Core.Scoping;
using Umbraco.Tests.TestHelpers;
using Umbraco.Tests.Testing;
@@ -3,8 +3,8 @@ using System.Linq;
using System.Text;
using Moq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Composing;
using Umbraco.Core.IO;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence.Repositories.Implement;
@@ -68,7 +68,7 @@ namespace Umbraco.Tests.Persistence.Repositories
// Act
var script = new Script("test-add-script.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" };
repository.Save(script);
//Assert
Assert.That(_fileSystem.FileExists("test-add-script.js"), Is.True);
@@ -87,11 +87,11 @@ namespace Umbraco.Tests.Persistence.Repositories
// Act
var script = new Script("test-updated-script.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" };
repository.Save(script);
script.Content = "/// <reference name=\"MicrosoftAjax-Updated.js\"/>";
repository.Save(script);
var scriptUpdated = repository.Get("test-updated-script.js");
@@ -113,7 +113,7 @@ namespace Umbraco.Tests.Persistence.Repositories
// Act
var script = repository.Get("test-script.js");
repository.Delete(script);
// Assert
@@ -155,7 +155,7 @@ namespace Umbraco.Tests.Persistence.Repositories
repository.Save(script2);
var script3 = new Script("test-script3.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" };
repository.Save(script3);
// Act
var scripts = repository.GetMany();
@@ -183,7 +183,7 @@ namespace Umbraco.Tests.Persistence.Repositories
repository.Save(script2);
var script3 = new Script("test-script3.js") { Content = "/// <reference name=\"MicrosoftAjax.js\"/>" };
repository.Save(script3);
// Act
var scripts = repository.GetMany("test-script1.js", "test-script2.js");
@@ -226,13 +226,13 @@ namespace Umbraco.Tests.Persistence.Repositories
var script = new Script("test-move-script.js") { Content = content };
repository.Save(script);
// Act
script = repository.Get("test-move-script.js");
script.Path = "moved/test-move-script.js";
repository.Save(script);
var existsOld = repository.Exists("test-move-script.js");
var existsNew = repository.Exists("moved/test-move-script.js");
@@ -259,7 +259,7 @@ namespace Umbraco.Tests.Persistence.Repositories
var script = new Script("test-path-1.js") { Content = "// script" };
repository.Save(script);
Assert.IsTrue(_fileSystem.FileExists("test-path-1.js"));
Assert.AreEqual("test-path-1.js", script.Path);
Assert.AreEqual("/scripts/test-path-1.js", script.VirtualPath);
@@ -267,14 +267,14 @@ namespace Umbraco.Tests.Persistence.Repositories
//ensure you can prefix the same path as the root path name
script = new Script("scripts/path-2/test-path-2.js") { Content = "// script" };
repository.Save(script);
Assert.IsTrue(_fileSystem.FileExists("scripts/path-2/test-path-2.js"));
Assert.AreEqual("scripts\\path-2\\test-path-2.js", script.Path);
Assert.AreEqual("/scripts/scripts/path-2/test-path-2.js", script.VirtualPath);
script = new Script("path-2/test-path-2.js") { Content = "// script" };
repository.Save(script);
Assert.IsTrue(_fileSystem.FileExists("path-2/test-path-2.js"));
Assert.AreEqual("path-2\\test-path-2.js", script.Path); // fixed in 7.3 - 7.2.8 does not update the path
Assert.AreEqual("/scripts/path-2/test-path-2.js", script.VirtualPath);
@@ -286,7 +286,7 @@ namespace Umbraco.Tests.Persistence.Repositories
script = new Script("path-2\\test-path-3.js") { Content = "// script" };
repository.Save(script);
Assert.IsTrue(_fileSystem.FileExists("path-2/test-path-3.js"));
Assert.AreEqual("path-2\\test-path-3.js", script.Path);
Assert.AreEqual("/scripts/path-2/test-path-3.js", script.VirtualPath);
@@ -1,9 +1,9 @@
using System;
using Moq;
using Moq;
using NUnit.Framework;
using Umbraco.Core.Models;
using Umbraco.Tests.TestHelpers;
using Umbraco.Web.Routing;
using Umbraco.Core;
namespace Umbraco.Tests.Routing
{
@@ -4,6 +4,7 @@ using System.Globalization;
using System.Linq;
using Moq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Models;
using Umbraco.Core.Models.PublishedContent;
@@ -2,7 +2,7 @@
using System.Linq;
using Moq;
using NUnit.Framework;
using Umbraco.Core.Composing;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Tests.TestHelpers;
@@ -3,12 +3,12 @@ using System.Collections.Generic;
using System.Linq;
using Moq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Core.Services;
using Umbraco.Tests.TestHelpers;
using Umbraco.Web.PublishedCache.XmlPublishedCache;
using Umbraco.Web.Routing;
using Umbraco.Core.Composing;
namespace Umbraco.Tests.Routing
{
@@ -1,12 +1,12 @@
using System;
using Moq;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Models;
using Umbraco.Tests.TestHelpers;
using Umbraco.Web.PublishedCache.XmlPublishedCache;
using Umbraco.Web.Routing;
using Umbraco.Core.Services;
using Umbraco.Core.Composing;
namespace Umbraco.Tests.Routing
{
@@ -6,6 +6,7 @@ using System.Web.Http;
using Moq;
using Newtonsoft.Json;
using NUnit.Framework;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Models;
using Umbraco.Core.Models.Membership;
@@ -41,7 +42,7 @@ namespace Umbraco.Tests.Web.Controllers
// kill the true IEntityService too
Container.RegisterSingleton(f => Mock.Of<IEntityService>());
Container.RegisterSingleton<UmbracoFeatures>();
}
@@ -68,7 +69,6 @@ namespace Umbraco.Tests.Web.Controllers
.Returns((int id) => id == 1234 ? new User(1234, "Test", "test@test.com", "test@test.com", "", new List<IReadOnlyUserGroup>(), new int[0], new int[0]) : null);
var usersController = new UsersController();
Container.InjectProperties(usersController);
return usersController;
}
@@ -125,7 +125,6 @@ namespace Umbraco.Tests.Web.Controllers
ApiController Factory(HttpRequestMessage message, UmbracoHelper helper)
{
var usersController = new UsersController();
Container.InjectProperties(usersController);
return usersController;
}
@@ -153,7 +152,6 @@ namespace Umbraco.Tests.Web.Controllers
.Returns(() => users);
var usersController = new UsersController();
Container.InjectProperties(usersController);
return usersController;
}
@@ -95,7 +95,6 @@ namespace Umbraco.Tests.Web.Mvc
var controller = new TestSurfaceController(umbracoContext);
Container.Register(_ => umbracoContext);
Container.InjectProperties(controller);
Assert.IsNotNull(controller.Umbraco);
}
@@ -187,7 +186,7 @@ namespace Umbraco.Tests.Web.Mvc
: base(ctx, null, new ServiceContext(), Mock.Of<CacheHelper>(), null, null)
{
if (helper != null)
{
{
Umbraco = helper;
}
}
@@ -2,6 +2,7 @@
using System.Web.Http;
using LightInject;
using Umbraco.Core.Composing;
using Umbraco.Core.Composing.LightInject;
namespace Umbraco.Web.Composing.LightInject
{
@@ -18,7 +19,7 @@ namespace Umbraco.Web.Composing.LightInject
{ }
/// <inheritdoc />
public override void ConfigureForWeb()
public override IContainer ConfigureForWeb()
{
// IoC setup for LightInject for MVC/WebApi
// see comments on MixedLightInjectScopeManagerProvider for explainations of what we are doing here
@@ -27,6 +28,8 @@ namespace Umbraco.Web.Composing.LightInject
Container.EnableMvc(); // does container.EnablePerWebRequestScope()
Container.ScopeManagerProvider = smp; // reverts - we will do it last (in WebRuntime)
Container.EnableWebApi(GlobalConfiguration.Configuration);
return this;
}
}
}
@@ -1,11 +1,10 @@
using LightInject;
using Umbraco.Core.Composing;
using Umbraco.Core.Composing;
namespace Umbraco.Web.Editors
{
internal class EditorValidatorCollectionBuilder : LazyCollectionBuilderBase<EditorValidatorCollectionBuilder, EditorValidatorCollection, IEditorValidator>
{
public EditorValidatorCollectionBuilder(IServiceContainer container)
public EditorValidatorCollectionBuilder(IContainer container)
: base(container)
{ }
@@ -1,12 +1,11 @@
using LightInject;
using Umbraco.Core.Composing;
using Umbraco.Core.Composing;
using Umbraco.Web.HealthCheck.NotificationMethods;
namespace Umbraco.Web.HealthCheck
{
internal class HealthCheckNotificationMethodCollectionBuilder : LazyCollectionBuilderBase<HealthCheckNotificationMethodCollectionBuilder, HealthCheckNotificationMethodCollection, IHealthCheckNotificationMethod>
{
public HealthCheckNotificationMethodCollectionBuilder(IServiceContainer container)
public HealthCheckNotificationMethodCollectionBuilder(IContainer container)
: base(container)
{ }
@@ -1,11 +1,10 @@
using LightInject;
using Umbraco.Core.Composing;
using Umbraco.Core.Composing;
namespace Umbraco.Web.HealthCheck
{
public class HealthCheckCollectionBuilder : LazyCollectionBuilderBase<HealthCheckCollectionBuilder, HealthCheckCollection, HealthCheck>
{
public HealthCheckCollectionBuilder(IServiceContainer container)
public HealthCheckCollectionBuilder(IContainer container)
: base(container)
{ }
@@ -13,6 +12,6 @@ namespace Umbraco.Web.HealthCheck
// note: in v7 they were per-request, not sure why?
// the collection is injected into the controller & there's only 1 controller per request anyways
protected override ILifetime CollectionLifetime => null; // transient!
protected override Lifetime CollectionLifetime => Lifetime.Transient; // transient!
}
}
@@ -1,11 +1,10 @@
using LightInject;
using Umbraco.Core.Composing;
using Umbraco.Core.Composing;
namespace Umbraco.Web.Mvc
{
public class FilteredControllerFactoryCollectionBuilder : OrderedCollectionBuilderBase<FilteredControllerFactoryCollectionBuilder, FilteredControllerFactoryCollection, IFilteredControllerFactory>
{
public FilteredControllerFactoryCollectionBuilder(IServiceContainer container)
public FilteredControllerFactoryCollectionBuilder(IContainer container)
: base(container)
{ }
@@ -1,11 +1,10 @@
using LightInject;
using Umbraco.Core.Composing;
using Umbraco.Core.Composing;
namespace Umbraco.Web.Routing
{
public class ContentFinderCollectionBuilder : OrderedCollectionBuilderBase<ContentFinderCollectionBuilder, ContentFinderCollection, IContentFinder>
{
public ContentFinderCollectionBuilder(IServiceContainer container)
public ContentFinderCollectionBuilder(IContainer container)
: base(container)
{ }
@@ -1,11 +1,10 @@
using LightInject;
using Umbraco.Core.Composing;
using Umbraco.Core.Composing;
namespace Umbraco.Web.Routing
{
public class UrlProviderCollectionBuilder : OrderedCollectionBuilderBase<UrlProviderCollectionBuilder, UrlProviderCollection, IUrlProvider>
{
public UrlProviderCollectionBuilder(IServiceContainer container)
public UrlProviderCollectionBuilder(IContainer container)
: base(container)
{ }
@@ -1,5 +1,4 @@
using LightInject;
using Umbraco.Core.Composing;
using Umbraco.Core.Composing;
using Umbraco.Core.Services;
using Umbraco.Web.Trees;
@@ -9,7 +8,7 @@ namespace Umbraco.Web.Search
{
private readonly IApplicationTreeService _treeService;
public SearchableTreeCollectionBuilder(IServiceContainer container, IApplicationTreeService treeService)
public SearchableTreeCollectionBuilder(IContainer container, IApplicationTreeService treeService)
: base(container)
{
_treeService = treeService;
@@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using LightInject;
using Umbraco.Core;
using Umbraco.Core.Composing;
@@ -18,14 +17,14 @@ namespace Umbraco.Web.Tour
/// <summary>
/// Initializes a new instance of the <see cref="TourFilterCollectionBuilder"/> class.
/// </summary>
public TourFilterCollectionBuilder(IServiceContainer container)
public TourFilterCollectionBuilder(IContainer container)
: base(container)
{ }
/// <inheritdoc />
protected override IEnumerable<BackOfficeTourFilter> CreateItems(params object[] args)
protected override IEnumerable<BackOfficeTourFilter> CreateItems(/*params object[] args*/)
{
return base.CreateItems(args).Concat(_instances);
return base.CreateItems(/*args*/).Concat(_instances);
}
/// <summary>