From 9e931b84db0631c105f165775802fbd54b749c19 Mon Sep 17 00:00:00 2001 From: Shannon Date: Wed, 10 Feb 2016 10:21:30 +0100 Subject: [PATCH] U4-7925 Add dependency injection to Umbraco.Web.Trees.TreeController* --- src/Umbraco.Web/Trees/TreeController.cs | 42 ++++++++++++------- src/Umbraco.Web/Trees/TreeControllerBase.cs | 12 ++++++ .../WebApi/UmbracoApiController.cs | 6 ++- .../WebApi/UmbracoAuthorizedApiController.cs | 10 +++-- 4 files changed, 51 insertions(+), 19 deletions(-) diff --git a/src/Umbraco.Web/Trees/TreeController.cs b/src/Umbraco.Web/Trees/TreeController.cs index aad0d8330d..0f975a9860 100644 --- a/src/Umbraco.Web/Trees/TreeController.cs +++ b/src/Umbraco.Web/Trees/TreeController.cs @@ -18,25 +18,23 @@ namespace Umbraco.Web.Trees /// public abstract class TreeController : TreeControllerBase { - private readonly TreeAttribute _attribute; + private TreeAttribute _attribute; protected TreeController() { - //Locate the tree attribute - var treeAttributes = GetType() - .GetCustomAttributes(typeof(TreeAttribute), false) - .OfType() - .ToArray(); - - if (treeAttributes.Any() == false) - { - throw new InvalidOperationException("The Tree controller is missing the " + typeof(TreeAttribute).FullName + " attribute"); - } - - //assign the properties of this object to those of the metadata attribute - _attribute = treeAttributes.First(); + Initialize(); } + protected TreeController(UmbracoContext umbracoContext) : base(umbracoContext) + { + Initialize(); + } + + protected TreeController(UmbracoContext umbracoContext, UmbracoHelper umbracoHelper) : base(umbracoContext, umbracoHelper) + { + Initialize(); + } + /// /// The name to display on the root node /// @@ -68,5 +66,21 @@ namespace Umbraco.Web.Trees get { return _attribute.Alias; } } + private void Initialize() + { + //Locate the tree attribute + var treeAttributes = GetType() + .GetCustomAttributes(typeof(TreeAttribute), false) + .OfType() + .ToArray(); + + if (treeAttributes.Any() == false) + { + throw new InvalidOperationException("The Tree controller is missing the " + typeof(TreeAttribute).FullName + " attribute"); + } + + //assign the properties of this object to those of the metadata attribute + _attribute = treeAttributes.First(); + } } } diff --git a/src/Umbraco.Web/Trees/TreeControllerBase.cs b/src/Umbraco.Web/Trees/TreeControllerBase.cs index 74b2ffc670..91191a165d 100644 --- a/src/Umbraco.Web/Trees/TreeControllerBase.cs +++ b/src/Umbraco.Web/Trees/TreeControllerBase.cs @@ -18,6 +18,18 @@ namespace Umbraco.Web.Trees [AngularJsonOnlyConfiguration] public abstract class TreeControllerBase : UmbracoAuthorizedApiController { + protected TreeControllerBase() + { + } + + protected TreeControllerBase(UmbracoContext umbracoContext) : base(umbracoContext) + { + } + + protected TreeControllerBase(UmbracoContext umbracoContext, UmbracoHelper umbracoHelper) : base(umbracoContext, umbracoHelper) + { + } + /// /// The method called to render the contents of the tree structure /// diff --git a/src/Umbraco.Web/WebApi/UmbracoApiController.cs b/src/Umbraco.Web/WebApi/UmbracoApiController.cs index d93c070cf4..b850532011 100644 --- a/src/Umbraco.Web/WebApi/UmbracoApiController.cs +++ b/src/Umbraco.Web/WebApi/UmbracoApiController.cs @@ -12,7 +12,7 @@ namespace Umbraco.Web.WebApi /// The base class for auto-routed API controllers for Umbraco /// public abstract class UmbracoApiController : UmbracoApiControllerBase - { + { protected UmbracoApiController() { } @@ -20,5 +20,9 @@ namespace Umbraco.Web.WebApi protected UmbracoApiController(UmbracoContext umbracoContext) : base(umbracoContext) { } + + protected UmbracoApiController(UmbracoContext umbracoContext, UmbracoHelper umbracoHelper) : base(umbracoContext, umbracoHelper) + { + } } } diff --git a/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs b/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs index ad29726d4e..924ec8bd2e 100644 --- a/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs +++ b/src/Umbraco.Web/WebApi/UmbracoAuthorizedApiController.cs @@ -22,14 +22,16 @@ namespace Umbraco.Web.WebApi { protected UmbracoAuthorizedApiController() { - } - protected UmbracoAuthorizedApiController(UmbracoContext umbracoContext) - : base(umbracoContext) + protected UmbracoAuthorizedApiController(UmbracoContext umbracoContext) : base(umbracoContext) { } - + + protected UmbracoAuthorizedApiController(UmbracoContext umbracoContext, UmbracoHelper umbracoHelper) : base(umbracoContext, umbracoHelper) + { + } + private bool _userisValidated = false; ///