diff --git a/src/Umbraco.Core/Composing/ContainerFactory.cs b/src/Umbraco.Core/Composing/ContainerFactory.cs
index 5c85072298..fb2c5f6eb7 100644
--- a/src/Umbraco.Core/Composing/ContainerFactory.cs
+++ b/src/Umbraco.Core/Composing/ContainerFactory.cs
@@ -1,36 +1,54 @@
using System;
using System.Configuration;
using System.Reflection;
-using Umbraco.Core.Composing.LightInject;
namespace Umbraco.Core.Composing
{
- public class ContainerFactory
+ ///
+ /// Creates the container.
+ ///
+ public static class ContainerFactory
{
+ // cannot use typeof().AssemblyQualifiedName on the web container - we don't reference it
+ // a normal Umbraco site should run on the web container, but an app may run on the core one
+ private const string CoreLightInjectContainerTypeName = "Umbraco.Core.Composing.LightInject.LightInjectContainer,Umbraco.Core";
+ private const string WebLightInjectContainerTypeName = "Umbraco.Web.Composing.LightInject.LightInjectContainer,Umbraco.Web";
+
///
/// Creates a new instance of the configured container.
+ ///
+ ///
/// To override the default LightInjectContainer, add an appSetting named umbracoContainerType with
/// a fully qualified type name to a class with a static method "Create" returning an IContainer.
- ///
+ ///
public static IContainer Create()
{
- var configuredTypeName = ConfigurationManager.AppSettings["umbracoContainerType"]
- ?? typeof(LightInjectContainer).AssemblyQualifiedName;
- var type = Type.GetType(configuredTypeName);
+ Type type;
+
+ var configuredTypeName = ConfigurationManager.AppSettings["umbracoContainerType"];
+ if (configuredTypeName.IsNullOrWhiteSpace())
+ {
+ // try to get the web LightInject container type,
+ // else the core LightInject container type
+ type = Type.GetType(configuredTypeName = WebLightInjectContainerTypeName) ??
+ Type.GetType(configuredTypeName = CoreLightInjectContainerTypeName);
+ }
+ else
+ {
+ // try to get the configured container type
+ type = Type.GetType(configuredTypeName);
+ }
+
if (type == null)
- {
- throw new Exception($"Cannot find container factory class named '${configuredTypeName}'");
- }
- var factoryMethod = type.GetMethod("Create", BindingFlags.Static);
+ throw new Exception($"Cannot find container factory class '{configuredTypeName}'.");
+
+ var factoryMethod = type.GetMethod("Create", BindingFlags.Public | BindingFlags.Static);
if (factoryMethod == null)
- {
- throw new Exception($"Container factory class '${configuredTypeName}' does not have a public static method named Create");
- }
- var container = factoryMethod.Invoke(null, new object[0]) as IContainer;
+ throw new Exception($"Container factory class '{configuredTypeName}' does not have a public static method named Create.");
+
+ var container = factoryMethod.Invoke(null, Array.Empty