Fix missing dependencies errors, simplify

This commit is contained in:
Stephan
2018-12-12 16:07:21 +01:00
parent 3e082f1a94
commit e40c9cb227
16 changed files with 137 additions and 49 deletions

View File

@@ -0,0 +1,38 @@
using System;
namespace Umbraco.Core
{
/// <summary>
/// Represents the main AppDomain running for a given application.
/// </summary>
/// <remarks>
/// <para>There can be only one "main" AppDomain running for a given application at a time.</para>
/// <para>It is possible to register against the MainDom and be notified when it is released.</para>
/// </remarks>
public interface IMainDom
{
/// <summary>
/// Gets a value indicating whether the current domain is the main domain.
/// </summary>
bool IsMainDom { get; }
/// <summary>
/// Registers a resource that requires the current AppDomain to be the main domain to function.
/// </summary>
/// <param name="release">An action to execute before the AppDomain releases the main domain status.</param>
/// <param name="weight">An optional weight (lower goes first).</param>
/// <returns>A value indicating whether it was possible to register.</returns>
bool Register(Action release, int weight = 100);
/// <summary>
/// Registers a resource that requires the current AppDomain to be the main domain to function.
/// </summary>
/// <param name="install">An action to execute when registering.</param>
/// <param name="release">An action to execute before the AppDomain releases the main domain status.</param>
/// <param name="weight">An optional weight (lower goes first).</param>
/// <returns>A value indicating whether it was possible to register.</returns>
/// <remarks>If registering is successful, then the <paramref name="install"/> action
/// is guaranteed to execute before the AppDomain releases the main domain status.</remarks>
bool Register(Action install, Action release, int weight = 100);
}
}

View File

@@ -8,13 +8,11 @@ using Umbraco.Core.Logging;
namespace Umbraco.Core namespace Umbraco.Core
{ {
/// <summary> /// <summary>
/// Represents the main AppDomain running for a given application. /// Provides the full implementation of <see cref="IMainDom"/>.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// <para>There can be only one "main" AppDomain running for a given application at a time.</para>
/// <para>When an AppDomain starts, it tries to acquire the main domain status.</para> /// <para>When an AppDomain starts, it tries to acquire the main domain status.</para>
/// <para>When an AppDomain stops (eg the application is restarting) it should release the main domain status.</para> /// <para>When an AppDomain stops (eg the application is restarting) it should release the main domain status.</para>
/// <para>It is possible to register against the MainDom and be notified when it is released.</para>
/// </remarks> /// </remarks>
internal class MainDom : IRegisteredObject internal class MainDom : IRegisteredObject
{ {
@@ -84,9 +82,7 @@ namespace Umbraco.Core
/// <param name="weight">An optional weight (lower goes first).</param> /// <param name="weight">An optional weight (lower goes first).</param>
/// <returns>A value indicating whether it was possible to register.</returns> /// <returns>A value indicating whether it was possible to register.</returns>
public bool Register(Action release, int weight = 100) public bool Register(Action release, int weight = 100)
{ => Register(null, release, weight);
return Register(null, release, weight);
}
/// <summary> /// <summary>
/// Registers a resource that requires the current AppDomain to be the main domain to function. /// Registers a resource that requires the current AppDomain to be the main domain to function.
@@ -195,7 +191,9 @@ namespace Umbraco.Core
} }
} }
// gets a value indicating whether we are the main domain /// <summary>
/// Gets a value indicating whether the current domain is the main domain.
/// </summary>
public bool IsMainDom => _isMainDom; public bool IsMainDom => _isMainDom;
// IRegisteredObject // IRegisteredObject

View File

@@ -66,7 +66,7 @@ namespace Umbraco.Core.Services.Implement
IEntityService entityService, IEntityService entityService,
IUserService userService, IUserService userService,
IScopeProvider scopeProvider, IScopeProvider scopeProvider,
IEnumerable<IUrlSegmentProvider> urlSegmentProviders, UrlSegmentProviderCollection urlSegmentProviders,
IAuditRepository auditRepository, IContentTypeRepository contentTypeRepository, IAuditRepository auditRepository, IContentTypeRepository contentTypeRepository,
PropertyEditorCollection propertyEditors) PropertyEditorCollection propertyEditors)
{ {

View File

@@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using System.Linq;
namespace Umbraco.Core
{
/// <summary>
/// Provides a simple implementation of <see cref="IMainDom"/>.
/// </summary>
public class SimpleMainDom : IMainDom
{
private readonly object _locko = new object();
private readonly List<KeyValuePair<int, Action>> _callbacks = new List<KeyValuePair<int, Action>>();
private bool _isStopping;
/// <inheritdoc />
public bool IsMainDom { get; private set; } = true;
/// <inheritdoc />
public bool Register(Action release, int weight = 100)
=> Register(null, release, weight);
/// <inheritdoc />
public bool Register(Action install, Action release, int weight = 100)
{
lock (_locko)
{
if (_isStopping) return false;
install?.Invoke();
if (release != null)
_callbacks.Add(new KeyValuePair<int, Action>(weight, release));
return true;
}
}
public void Stop()
{
lock (_locko)
{
if (_isStopping) return;
if (IsMainDom == false) return; // probably not needed
_isStopping = true;
}
try
{
foreach (var callback in _callbacks.OrderBy(x => x.Key).Select(x => x.Value))
{
callback(); // no timeout on callbacks
}
}
finally
{
// in any case...
IsMainDom = false;
}
}
}
}

View File

@@ -329,6 +329,7 @@
<Compile Include="Events\ExportedMemberEventArgs.cs" /> <Compile Include="Events\ExportedMemberEventArgs.cs" />
<Compile Include="Events\RolesEventArgs.cs" /> <Compile Include="Events\RolesEventArgs.cs" />
<Compile Include="Events\UserGroupWithUsers.cs" /> <Compile Include="Events\UserGroupWithUsers.cs" />
<Compile Include="IMainDom.cs" />
<Compile Include="IO\IFileSystems.cs" /> <Compile Include="IO\IFileSystems.cs" />
<Compile Include="IO\IMediaFileSystem.cs" /> <Compile Include="IO\IMediaFileSystem.cs" />
<Compile Include="GuidUtils.cs" /> <Compile Include="GuidUtils.cs" />
@@ -1431,6 +1432,7 @@
<Compile Include="Components\ManifestWatcherComponent.cs" /> <Compile Include="Components\ManifestWatcherComponent.cs" />
<Compile Include="Components\RelateOnCopyComponent.cs" /> <Compile Include="Components\RelateOnCopyComponent.cs" />
<Compile Include="Components\RelateOnTrashComponent.cs" /> <Compile Include="Components\RelateOnTrashComponent.cs" />
<Compile Include="SimpleMainDom.cs" />
<Compile Include="StringExtensions.cs" /> <Compile Include="StringExtensions.cs" />
<Compile Include="Strings\CleanStringType.cs" /> <Compile Include="Strings\CleanStringType.cs" />
<Compile Include="Strings\ContentBaseExtensions.cs" /> <Compile Include="Strings\ContentBaseExtensions.cs" />

View File

@@ -14,7 +14,7 @@ namespace Umbraco.Examine
private readonly IUserService _userService; private readonly IUserService _userService;
public MediaValueSetBuilder(PropertyEditorCollection propertyEditors, public MediaValueSetBuilder(PropertyEditorCollection propertyEditors,
IEnumerable<IUrlSegmentProvider> urlSegmentProviders, UrlSegmentProviderCollection urlSegmentProviders,
IUserService userService) IUserService userService)
: base(propertyEditors, false) : base(propertyEditors, false)
{ {

View File

@@ -136,8 +136,8 @@ Ensure that 'NameSpace.IBar' is registered with a lifetime that is equal to or h
{ {
var serviceType = validationTarget.ServiceType.GenericTypeArguments[0]; var serviceType = validationTarget.ServiceType.GenericTypeArguments[0];
var underlyingvalidationTarget = validationTarget.WithServiceDescription(serviceType, string.Empty); var underlyingvalidationTarget = validationTarget.WithServiceDescription(serviceType, string.Empty);
registration = GetServiceRegistration(serviceMap, underlyingvalidationTarget); var registrations = GetServiceRegistrations(serviceMap, underlyingvalidationTarget);
if (registration != null) return; if (registrations.Any()) return;
// strict: there has to be at least 1 // strict: there has to be at least 1
string message = string.Format(MissingDeferredDependency, validationTarget.ServiceType, underlyingvalidationTarget.ServiceType); string message = string.Format(MissingDeferredDependency, validationTarget.ServiceType, underlyingvalidationTarget.ServiceType);
@@ -198,9 +198,13 @@ Ensure that 'NameSpace.IBar' is registered with a lifetime that is equal to or h
LifeSpans.TryAdd(typeof(TLifetime), lifeSpan); LifeSpans.TryAdd(typeof(TLifetime), lifeSpan);
} }
private static IEnumerable<ServiceRegistration> GetServiceRegistrations(ServiceMap serviceMap, ValidationTarget validationTarget)
{
return serviceMap.Where(x => validationTarget.ServiceType.IsAssignableFrom(x.Key)).SelectMany(x => x.Value.Values);
}
private static ServiceRegistration GetServiceRegistration(ServiceMap serviceMap, ValidationTarget validationTarget) private static ServiceRegistration GetServiceRegistration(ServiceMap serviceMap, ValidationTarget validationTarget)
{ {
if (!serviceMap.TryGetValue(validationTarget.ServiceType, out var registrations)) if (!serviceMap.TryGetValue(validationTarget.ServiceType, out var registrations))
{ {
return null; return null;
@@ -224,8 +228,6 @@ Ensure that 'NameSpace.IBar' is registered with a lifetime that is equal to or h
return null; return null;
} }
private static string GetLifetimeName(ILifetime lifetime) private static string GetLifetimeName(ILifetime lifetime)
{ {
if (lifetime == null) if (lifetime == null)
@@ -235,7 +237,6 @@ Ensure that 'NameSpace.IBar' is registered with a lifetime that is equal to or h
return lifetime.GetType().Name; return lifetime.GetType().Name;
} }
private static int GetLifespan(ILifetime lifetime) private static int GetLifespan(ILifetime lifetime)
{ {
if (lifetime == null) if (lifetime == null)
@@ -248,9 +249,6 @@ Ensure that 'NameSpace.IBar' is registered with a lifetime that is equal to or h
} }
return 0; return 0;
} }
} }

View File

@@ -22,6 +22,7 @@ namespace Umbraco.Tests.Runtimes
public class StandaloneTests public class StandaloneTests
{ {
[Test] [Test]
[Explicit("This test must be run manually")]
public void Test() public void Test()
{ {
// this is almost what CoreRuntime does, without // this is almost what CoreRuntime does, without
@@ -53,9 +54,12 @@ namespace Umbraco.Tests.Runtimes
// at that point, CoreRuntime also does // at that point, CoreRuntime also does
//composition.RegisterUnique(mainDom) //composition.RegisterUnique(mainDom)
// we should make it // we should make it
//composition.RegisterUnique<IMainDom>(mainDom) composition.RegisterUnique(Mock.Of<IMainDom>());
//composition.RegisterUnique<IMainDom>(new SimpleMainDom());
// because some components want to use it // because some components want to use it
// (and then, what would a standalone maindom be?) // (and then, what would a standalone maindom be?)
//
// is this an essential thing then??
// get the components // get the components
// all of them? // all of them?
@@ -84,13 +88,13 @@ namespace Umbraco.Tests.Runtimes
// and then, validate // and then, validate
var lightInjectContainer = (LightInject.ServiceContainer) factory.Concrete; var lightInjectContainer = (LightInject.ServiceContainer) factory.Concrete;
var results = lightInjectContainer.Validate().ToList(); var results = lightInjectContainer.Validate().ToList();
foreach (var resultGroup in results.GroupBy(x => x.Severity)) foreach (var resultGroup in results.GroupBy(x => x.Severity).OrderBy(x => x.Key))
foreach (var result in resultGroup) foreach (var result in resultGroup)
{ {
Console.WriteLine(); Console.WriteLine();
Console.WriteLine($"{result.Severity}: {WordWrap(result.Message, 120)}"); Console.WriteLine($"{result.Severity}: {WordWrap(result.Message, 120)}");
var target = result.ValidationTarget; var target = result.ValidationTarget;
Console.Write("\t"); Console.Write("\tsvce: ");
Console.Write(target.ServiceName); Console.Write(target.ServiceName);
Console.Write(target.DeclaringService.ServiceType); Console.Write(target.DeclaringService.ServiceType);
if (!target.DeclaringService.ServiceName.IsNullOrWhiteSpace()) if (!target.DeclaringService.ServiceName.IsNullOrWhiteSpace())
@@ -100,13 +104,15 @@ namespace Umbraco.Tests.Runtimes
Console.Write("'"); Console.Write("'");
} }
Console.Write(" "); Console.Write(" (");
if (target.DeclaringService.Lifetime == null) if (target.DeclaringService.Lifetime == null)
Console.Write("?"); Console.Write("?");
else else
Console.Write(target.DeclaringService.Lifetime.ToString().TrimStart("LightInject.")); Console.Write(target.DeclaringService.Lifetime.ToString().TrimStart("LightInject."));
Console.WriteLine(); Console.WriteLine(")");
Console.Write("\t"); Console.Write("\timpl: ");
Console.WriteLine(target.DeclaringService.ImplementingType);
Console.Write("\tparm: ");
Console.Write(target.Parameter); Console.Write(target.Parameter);
Console.WriteLine(); Console.WriteLine();
} }

View File

@@ -91,7 +91,7 @@ namespace Umbraco.Tests.TestHelpers
IGlobalSettings globalSettings, IGlobalSettings globalSettings,
IUmbracoSettingsSection umbracoSettings, IUmbracoSettingsSection umbracoSettings,
IEventMessagesFactory eventMessagesFactory, IEventMessagesFactory eventMessagesFactory,
IEnumerable<IUrlSegmentProvider> urlSegmentProviders, UrlSegmentProviderCollection urlSegmentProviders,
TypeLoader typeLoader, TypeLoader typeLoader,
IFactory factory = null) IFactory factory = null)
{ {

View File

@@ -44,7 +44,7 @@ namespace Umbraco.Tests.UmbracoExamine
public static MediaIndexPopulator GetMediaIndexRebuilder(PropertyEditorCollection propertyEditors, IMediaService mediaService) public static MediaIndexPopulator GetMediaIndexRebuilder(PropertyEditorCollection propertyEditors, IMediaService mediaService)
{ {
var mediaValueSetBuilder = new MediaValueSetBuilder(propertyEditors, new[] { new DefaultUrlSegmentProvider() }, GetMockUserService()); var mediaValueSetBuilder = new MediaValueSetBuilder(propertyEditors, new UrlSegmentProviderCollection(new[] { new DefaultUrlSegmentProvider() }), GetMockUserService());
var mediaIndexDataSource = new MediaIndexPopulator(null, mediaService, mediaValueSetBuilder); var mediaIndexDataSource = new MediaIndexPopulator(null, mediaService, mediaValueSetBuilder);
return mediaIndexDataSource; return mediaIndexDataSource;
} }
@@ -161,7 +161,7 @@ namespace Umbraco.Tests.UmbracoExamine
if (validator == null) if (validator == null)
validator = new ContentValueSetValidator(true); validator = new ContentValueSetValidator(true);
var i = new UmbracoContentIndex( var i = new UmbracoContentIndex(
"testIndexer", "testIndexer",
UmbracoExamineIndex.UmbracoIndexFieldDefinitions, UmbracoExamineIndex.UmbracoIndexFieldDefinitions,

View File

@@ -2,6 +2,7 @@
using Umbraco.Core.Composing; using Umbraco.Core.Composing;
using Umbraco.Web.Install; using Umbraco.Web.Install;
using Umbraco.Web.Install.InstallSteps; using Umbraco.Web.Install.InstallSteps;
using Umbraco.Web.Install.Models;
namespace Umbraco.Web.Composing.Composers namespace Umbraco.Web.Composing.Composers
{ {

View File

@@ -2,14 +2,16 @@
using Umbraco.Web.Models; using Umbraco.Web.Models;
using Umbraco.Web.Mvc; using Umbraco.Web.Mvc;
using System.Linq; using System.Linq;
using Umbraco.Core.Composing;
using Umbraco.Core.Models.PublishedContent; using Umbraco.Core.Models.PublishedContent;
namespace Umbraco.Web.Macros namespace Umbraco.Web.Macros
{ {
/// <summary> /// <summary>
/// Controller to render macro content for Parital View Macros /// Controller to render macro content for Partial View Macros
/// </summary> /// </summary>
[MergeParentContextViewData] [MergeParentContextViewData]
[HideFromTypeFinder] // explicitly used: do *not* find and register it!
internal class PartialViewMacroController : Controller internal class PartialViewMacroController : Controller
{ {
private readonly MacroModel _macro; private readonly MacroModel _macro;

View File

@@ -37,15 +37,6 @@ namespace Umbraco.Web.Models.Mapping
_userService = userService ?? throw new System.ArgumentNullException(nameof(userService)); _userService = userService ?? throw new System.ArgumentNullException(nameof(userService));
} }
public MemberTabsAndPropertiesResolver(IUmbracoContextAccessor umbracoContextAccessor, ILocalizedTextService localizedTextService, IEnumerable<string> ignoreProperties, IMemberService memberService, IUserService userService)
: base(localizedTextService, ignoreProperties)
{
_umbracoContextAccessor = umbracoContextAccessor ?? throw new System.ArgumentNullException(nameof(umbracoContextAccessor));
_localizedTextService = localizedTextService ?? throw new System.ArgumentNullException(nameof(localizedTextService));
_memberService = memberService ?? throw new System.ArgumentNullException(nameof(memberService));
_userService = userService ?? throw new System.ArgumentNullException(nameof(userService));
}
/// <inheritdoc /> /// <inheritdoc />
/// <remarks>Overriden to deal with custom member properties and permissions.</remarks> /// <remarks>Overriden to deal with custom member properties and permissions.</remarks>
public override IEnumerable<Tab<ContentPropertyDisplay>> Resolve(IMember source, MemberDisplay destination, IEnumerable<Tab<ContentPropertyDisplay>> destMember, ResolutionContext context) public override IEnumerable<Tab<ContentPropertyDisplay>> Resolve(IMember source, MemberDisplay destination, IEnumerable<Tab<ContentPropertyDisplay>> destMember, ResolutionContext context)

View File

@@ -27,7 +27,7 @@ namespace Umbraco.Web.Models.Mapping
IgnoreProperties = ignoreProperties ?? throw new ArgumentNullException(nameof(ignoreProperties)); IgnoreProperties = ignoreProperties ?? throw new ArgumentNullException(nameof(ignoreProperties));
} }
//TODO: This should deserialize to ListViewConfiguration //TODO: This should deserialize to ListViewConfiguration
private static int GetTabNumberFromConfig(IDictionary<string, object> listViewConfig) private static int GetTabNumberFromConfig(IDictionary<string, object> listViewConfig)
{ {
if (!listViewConfig.TryGetValue("displayAtTabNumber", out var displayTabNum)) if (!listViewConfig.TryGetValue("displayAtTabNumber", out var displayTabNum))
@@ -139,13 +139,7 @@ namespace Umbraco.Web.Models.Mapping
{ {
public TabsAndPropertiesResolver(ILocalizedTextService localizedTextService) public TabsAndPropertiesResolver(ILocalizedTextService localizedTextService)
: base(localizedTextService) : base(localizedTextService)
{ { }
}
public TabsAndPropertiesResolver(ILocalizedTextService localizedTextService, IEnumerable<string> ignoreProperties)
: base(localizedTextService, ignoreProperties)
{
}
public virtual IEnumerable<Tab<ContentPropertyDisplay>> Resolve(TSource source, TDestination destination, IEnumerable<Tab<ContentPropertyDisplay>> destMember, ResolutionContext context) public virtual IEnumerable<Tab<ContentPropertyDisplay>> Resolve(TSource source, TDestination destination, IEnumerable<Tab<ContentPropertyDisplay>> destMember, ResolutionContext context)
{ {

View File

@@ -79,7 +79,7 @@ namespace Umbraco.Web.PublishedCache.NuCache
//private static int _singletonCheck; //private static int _singletonCheck;
public PublishedSnapshotService(Options options, MainDom mainDom, IRuntimeState runtime, public PublishedSnapshotService(Options options, IMainDom mainDom, IRuntimeState runtime,
ServiceContext serviceContext, IPublishedContentTypeFactory publishedContentTypeFactory, IdkMap idkMap, ServiceContext serviceContext, IPublishedContentTypeFactory publishedContentTypeFactory, IdkMap idkMap,
IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor, IPublishedSnapshotAccessor publishedSnapshotAccessor, IVariationContextAccessor variationContextAccessor,
ILogger logger, IScopeProvider scopeProvider, ILogger logger, IScopeProvider scopeProvider,

View File

@@ -40,8 +40,7 @@ namespace Umbraco.Web.Routing
IContentLastChanceFinder contentLastChanceFinder, IContentLastChanceFinder contentLastChanceFinder,
IVariationContextAccessor variationContextAccessor, IVariationContextAccessor variationContextAccessor,
ServiceContext services, ServiceContext services,
IProfilingLogger proflog, IProfilingLogger proflog)
Func<string, IEnumerable<string>> getRolesForLogin = null)
{ {
_webRoutingSection = webRoutingSection ?? throw new ArgumentNullException(nameof(webRoutingSection)); _webRoutingSection = webRoutingSection ?? throw new ArgumentNullException(nameof(webRoutingSection));
_contentFinders = contentFinders ?? throw new ArgumentNullException(nameof(contentFinders)); _contentFinders = contentFinders ?? throw new ArgumentNullException(nameof(contentFinders));
@@ -51,7 +50,7 @@ namespace Umbraco.Web.Routing
_variationContextAccessor = variationContextAccessor ?? throw new ArgumentNullException(nameof(variationContextAccessor)); _variationContextAccessor = variationContextAccessor ?? throw new ArgumentNullException(nameof(variationContextAccessor));
_logger = proflog; _logger = proflog;
GetRolesForLogin = getRolesForLogin ?? (s => Roles.Provider.GetRolesForUser(s)); GetRolesForLogin = s => Roles.Provider.GetRolesForUser(s);
} }
// fixme // fixme