diff --git a/src/Umbraco.Core/Components/Composers.cs b/src/Umbraco.Core/Components/Composers.cs
index 0dbd95b84c..1c836e9e5c 100644
--- a/src/Umbraco.Core/Components/Composers.cs
+++ b/src/Umbraco.Core/Components/Composers.cs
@@ -4,10 +4,7 @@ using System.Linq;
using System.Reflection;
using System.Text;
using Umbraco.Core.Collections;
-using Umbraco.Core.Composing;
-using Umbraco.Core.Exceptions;
using Umbraco.Core.Logging;
-using Umbraco.Core.Scoping;
namespace Umbraco.Core.Components
{
@@ -16,7 +13,7 @@ namespace Umbraco.Core.Components
///
/// Handles the composers.
///
- internal class Composers
+ public class Composers
{
private readonly Composition _composition;
private readonly IProfilingLogger _logger;
diff --git a/src/Umbraco.Core/Services/ServiceContext.cs b/src/Umbraco.Core/Services/ServiceContext.cs
index 88d55b4f0d..731d3a58c6 100644
--- a/src/Umbraco.Core/Services/ServiceContext.cs
+++ b/src/Umbraco.Core/Services/ServiceContext.cs
@@ -38,7 +38,6 @@ namespace Umbraco.Core.Services
///
/// Initializes a new instance of the class with lazy services.
///
- /// Used by IoC. Note that LightInject will favor lazy args when picking a constructor.
public ServiceContext(Lazy publicAccessService, Lazy domainService, Lazy auditService, Lazy localizedTextService, Lazy tagService, Lazy contentService, Lazy userService, Lazy memberService, Lazy mediaService, Lazy contentTypeService, Lazy mediaTypeService, Lazy dataTypeService, Lazy fileService, Lazy localizationService, Lazy packagingService, Lazy serverRegistrationService, Lazy entityService, Lazy relationService, Lazy treeService, Lazy sectionService, Lazy macroService, Lazy memberTypeService, Lazy memberGroupService, Lazy notificationService, Lazy externalLoginService, Lazy redirectUrlService, Lazy consentService)
{
_publicAccessService = publicAccessService;
@@ -71,10 +70,13 @@ namespace Umbraco.Core.Services
}
///
- /// Initializes a new instance of the class with services.
+ /// Creates a partial service context with only some services (for tests).
///
- /// Used in tests. All items are optional and remain null if not specified.
- internal ServiceContext(IContentService contentService = null,
+ ///
+ /// Using a true constructor for this confuses DI containers.
+ ///
+ public static ServiceContext CreatePartial(
+ IContentService contentService = null,
IMediaService mediaService = null,
IContentTypeService contentTypeService = null,
IMediaTypeService mediaTypeService = null,
@@ -102,40 +104,43 @@ namespace Umbraco.Core.Services
IRedirectUrlService redirectUrlService = null,
IConsentService consentService = null)
{
- if (serverRegistrationService != null) _serverRegistrationService = new Lazy(() => serverRegistrationService);
- if (externalLoginService != null) _externalLoginService = new Lazy(() => externalLoginService);
- if (auditService != null) _auditService = new Lazy(() => auditService);
- if (localizedTextService != null) _localizedTextService = new Lazy(() => localizedTextService);
- if (tagService != null) _tagService = new Lazy(() => tagService);
- if (contentService != null) _contentService = new Lazy(() => contentService);
- if (mediaService != null) _mediaService = new Lazy(() => mediaService);
- if (contentTypeService != null) _contentTypeService = new Lazy(() => contentTypeService);
- if (mediaTypeService != null) _mediaTypeService = new Lazy(() => mediaTypeService);
- if (dataTypeService != null) _dataTypeService = new Lazy(() => dataTypeService);
- if (fileService != null) _fileService = new Lazy(() => fileService);
- if (localizationService != null) _localizationService = new Lazy(() => localizationService);
- if (packagingService != null) _packagingService = new Lazy(() => packagingService);
- if (entityService != null) _entityService = new Lazy(() => entityService);
- if (relationService != null) _relationService = new Lazy(() => relationService);
- if (sectionService != null) _sectionService = new Lazy(() => sectionService);
- if (memberGroupService != null) _memberGroupService = new Lazy(() => memberGroupService);
- if (memberTypeService != null) _memberTypeService = new Lazy(() => memberTypeService);
- if (treeService != null) _treeService = new Lazy(() => treeService);
- if (memberService != null) _memberService = new Lazy(() => memberService);
- if (userService != null) _userService = new Lazy(() => userService);
- if (notificationService != null) _notificationService = new Lazy(() => notificationService);
- if (domainService != null) _domainService = new Lazy(() => domainService);
- if (macroService != null) _macroService = new Lazy(() => macroService);
- if (publicAccessService != null) _publicAccessService = new Lazy(() => publicAccessService);
- if (redirectUrlService != null) _redirectUrlService = new Lazy(() => redirectUrlService);
- if (consentService != null) _consentService = new Lazy(() => consentService);
+ Lazy Lazy(T service) => service == null ? null : new Lazy(() => service);
+
+ return new ServiceContext(
+ Lazy(publicAccessService),
+ Lazy(domainService),
+ Lazy(auditService),
+ Lazy(localizedTextService),
+ Lazy(tagService),
+ Lazy(contentService),
+ Lazy(userService),
+ Lazy(memberService),
+ Lazy(mediaService),
+ Lazy(contentTypeService),
+ Lazy(mediaTypeService),
+ Lazy(dataTypeService),
+ Lazy(fileService),
+ Lazy(localizationService),
+ Lazy(packagingService),
+ Lazy(serverRegistrationService),
+ Lazy(entityService),
+ Lazy(relationService),
+ Lazy(treeService),
+ Lazy(sectionService),
+ Lazy(macroService),
+ Lazy(memberTypeService),
+ Lazy(memberGroupService),
+ Lazy(notificationService),
+ Lazy(externalLoginService),
+ Lazy(redirectUrlService),
+ Lazy(consentService));
}
///
/// Gets the
///
public IPublicAccessService PublicAccessService => _publicAccessService.Value;
-
+
///
/// Gets the
///
diff --git a/src/Umbraco.Tests/Manifest/ManifestParserTests.cs b/src/Umbraco.Tests/Manifest/ManifestParserTests.cs
index 7acc9298a5..ce3d1d705c 100644
--- a/src/Umbraco.Tests/Manifest/ManifestParserTests.cs
+++ b/src/Umbraco.Tests/Manifest/ManifestParserTests.cs
@@ -28,7 +28,7 @@ namespace Umbraco.Tests.Manifest
var factory = Mock.Of();
Current.Factory = factory;
- var serviceContext = new ServiceContext(
+ var serviceContext = ServiceContext.CreatePartial(
localizedTextService: Mock.Of());
Mock.Get(factory)
diff --git a/src/Umbraco.Tests/Models/VariationTests.cs b/src/Umbraco.Tests/Models/VariationTests.cs
index 3fdd3ee0db..f5ba7f5915 100644
--- a/src/Umbraco.Tests/Models/VariationTests.cs
+++ b/src/Umbraco.Tests/Models/VariationTests.cs
@@ -45,7 +45,7 @@ namespace Umbraco.Tests.Models
.Setup(x => x.GetDataType(It.IsAny()))
.Returns(x => dataType);
- var serviceContext = new ServiceContext(
+ var serviceContext = ServiceContext.CreatePartial(
dataTypeService: dataTypeService,
localizedTextService: Mock.Of());
diff --git a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs
index 15ac7ab328..d12699efb7 100644
--- a/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs
+++ b/src/Umbraco.Tests/PublishedContent/NuCacheTests.cs
@@ -102,7 +102,7 @@ namespace Umbraco.Tests.PublishedContent
Mock.Get(dataTypeService).Setup(x => x.GetAll()).Returns(dataTypes);
// create a service context
- var serviceContext = new ServiceContext(
+ var serviceContext = ServiceContext.CreatePartial(
dataTypeService : dataTypeService,
memberTypeService: Mock.Of(),
memberService: Mock.Of(),
diff --git a/src/Umbraco.Tests/TestHelpers/BaseWebTest.cs b/src/Umbraco.Tests/TestHelpers/BaseWebTest.cs
index d969f8c3d3..f7e3744600 100644
--- a/src/Umbraco.Tests/TestHelpers/BaseWebTest.cs
+++ b/src/Umbraco.Tests/TestHelpers/BaseWebTest.cs
@@ -97,7 +97,7 @@ namespace Umbraco.Tests.TestHelpers
contentFinders ?? new ContentFinderCollection(Enumerable.Empty()),
new TestLastChanceFinder(),
new TestVariationContextAccessor(),
- container?.TryGetInstance() ?? new ServiceContext(),
+ container?.TryGetInstance() ?? ServiceContext.CreatePartial(),
new ProfilingLogger(Mock.Of(), Mock.Of()));
}
}
diff --git a/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs b/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs
index d6dad4c77f..9e2a2156ee 100644
--- a/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs
+++ b/src/Umbraco.Tests/TestHelpers/ControllerTesting/TestControllerActivatorBase.cs
@@ -51,7 +51,7 @@ namespace Umbraco.Tests.TestHelpers.ControllerTesting
var mockedDataTypeService = Mock.Of();
var mockedContentTypeService = Mock.Of();
- var serviceContext = new ServiceContext(
+ var serviceContext = ServiceContext.CreatePartial(
userService: mockedUserService,
contentService: mockedContentService,
mediaService: mockedMediaService,
diff --git a/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs b/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs
index 57bf940bc0..8c230f98d0 100644
--- a/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs
+++ b/src/Umbraco.Tests/TestHelpers/TestObjects-Mocks.cs
@@ -58,7 +58,7 @@ namespace Umbraco.Tests.TestHelpers
// fixme - else some tests break - figure it out
container = null;
- return new ServiceContext(
+ return ServiceContext.CreatePartial(
MockService(container),
MockService(container),
MockService(container),
diff --git a/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs b/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs
index 6cb92a7cfb..c413cb0e94 100644
--- a/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs
+++ b/src/Umbraco.Tests/Testing/TestingTests/MockTests.cs
@@ -66,7 +66,7 @@ namespace Umbraco.Tests.Testing.TestingTests
Mock.Of(),
Mock.Of(),
new MembershipHelper(new TestUmbracoContextAccessor(umbracoContext), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), null, Mock.Of(), Mock.Of()),
- new ServiceContext());
+ ServiceContext.CreatePartial());
Assert.Pass();
}
diff --git a/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs b/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs
index f833e39d5a..35e8f0a937 100644
--- a/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs
+++ b/src/Umbraco.Tests/Web/Mvc/SurfaceControllerTests.cs
@@ -133,7 +133,7 @@ namespace Umbraco.Tests.Web.Mvc
Mock.Of(),
Mock.Of(),
new MembershipHelper(new TestUmbracoContextAccessor(umbracoContext), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), Mock.Of(), null, Mock.Of(), Mock.Of()),
- new ServiceContext());
+ ServiceContext.CreatePartial());
var ctrl = new TestSurfaceController(umbracoContext, helper);
var result = ctrl.GetContent(2) as PublishedContentResult;
@@ -185,7 +185,7 @@ namespace Umbraco.Tests.Web.Mvc
public class TestSurfaceController : SurfaceController
{
public TestSurfaceController(UmbracoContext ctx, UmbracoHelper helper = null)
- : base(ctx, null, new ServiceContext(), Mock.Of(), null, null)
+ : base(ctx, null, ServiceContext.CreatePartial(), Mock.Of(), null, null)
{
if (helper != null)
{
diff --git a/src/Umbraco.Tests/Web/TemplateUtilitiesTests.cs b/src/Umbraco.Tests/Web/TemplateUtilitiesTests.cs
index 8081105bd1..7b640fae95 100644
--- a/src/Umbraco.Tests/Web/TemplateUtilitiesTests.cs
+++ b/src/Umbraco.Tests/Web/TemplateUtilitiesTests.cs
@@ -34,7 +34,7 @@ namespace Umbraco.Tests.Web
// should not depend on more than IdkMap maybe - fix this!
var entityService = new Mock();
entityService.Setup(x => x.GetId(It.IsAny(), It.IsAny())).Returns(Attempt.Fail());
- var serviceContext = new ServiceContext(entityService: entityService.Object);
+ var serviceContext = ServiceContext.CreatePartial(entityService: entityService.Object);
// fixme - bad in a unit test - but Udi has a static ctor that wants it?!
var container = new Mock();