Replaced base controller factory with one using the container o:)

This commit is contained in:
Lars-Erik Aabech
2018-09-09 22:34:20 +02:00
parent 57d22a87c0
commit 4ffcdf6943
6 changed files with 46 additions and 2 deletions

View File

@@ -169,5 +169,7 @@ namespace Umbraco.Core.Composing
IContainer EnablePerWebRequestScope();
#endregion
void Release(object instance);
}
}

View File

@@ -314,6 +314,11 @@ namespace Umbraco.Core.Composing.LightInject
#endregion
public void Release(object instance)
{
// fixme - no idea how to do this with LI
}
#region Control
/// <inheritdoc />

View File

@@ -0,0 +1,28 @@
using System;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.SessionState;
using Umbraco.Core.Composing;
namespace Umbraco.Web.Mvc
{
public class ContainerControllerFactory : DefaultControllerFactory
{
private readonly IContainer container;
public ContainerControllerFactory(IContainer container)
{
this.container = container;
}
protected override IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
return (IController)container.GetInstance(controllerType);
}
public override void ReleaseController(IController controller)
{
container.Release(controller);
}
}
}

View File

@@ -2,6 +2,7 @@
using System.Linq;
using System.Web.Mvc;
using System.Web.Routing;
using Umbraco.Web.Composing;
namespace Umbraco.Web.Mvc
{
@@ -11,7 +12,7 @@ namespace Umbraco.Web.Mvc
/// request. Allows circumvention of MVC3's singly registered IControllerFactory.
/// </summary>
/// <remarks></remarks>
internal class MasterControllerFactory : DefaultControllerFactory
internal class MasterControllerFactory : ContainerControllerFactory
{
private readonly Func<FilteredControllerFactoryCollection> _factoriesAccessor;
private FilteredControllerFactoryCollection _factories;
@@ -21,6 +22,7 @@ namespace Umbraco.Web.Mvc
/// </summary>
/// <param name="factoriesAccessor">The factories accessor.</param>
public MasterControllerFactory(Func<FilteredControllerFactoryCollection> factoriesAccessor)
: base(Current.Container)
{
// note
// because the MasterControllerFactory needs to be ctored to be assigned to

View File

@@ -65,8 +65,14 @@ namespace Umbraco.Web.Mvc
/// this nested class changes the visibility of <see cref="DefaultControllerFactory"/>'s internal methods in order to not have to rely on a try-catch.
/// </summary>
/// <remarks></remarks>
internal class OverridenDefaultControllerFactory : DefaultControllerFactory
internal class OverridenDefaultControllerFactory : ContainerControllerFactory
// DefaultControllerFactory
{
public OverridenDefaultControllerFactory()
: base(Current.Container)
{
}
public new IController GetControllerInstance(RequestContext requestContext, Type controllerType)
{
return base.GetControllerInstance(requestContext, controllerType);

View File

@@ -116,6 +116,7 @@
<Compile Include="Editors\BackOfficeServerVariables.cs" />
<Compile Include="Models\ContentEditing\ContentSavedState.cs" />
<Compile Include="Models\Mapping\ContentSavedStateResolver.cs" />
<Compile Include="Mvc\ContainerControllerFactory.cs" />
<Compile Include="WebApi\HttpActionContextExtensions.cs" />
<Compile Include="Models\ContentEditing\IContentSave.cs" />
<Compile Include="WebApi\TrimModelBinder.cs" />