From a8c5cd425d14e936eaefaa2c082b390187e52ce3 Mon Sep 17 00:00:00 2001 From: Lars-Erik Aabech Date: Thu, 14 Jun 2018 18:46:25 +0200 Subject: [PATCH] DataTypeValidateAttribute now uses bastard injection. Notes on the UmbracoModule. Need to abstract resolving via Current.Container to remove LightInject refs. --- .../Routing/UmbracoModuleTests.cs | 3 ++- .../Editors/DataTypeValidateAttribute.cs | 27 ++++++++++++++----- src/Umbraco.Web/UmbracoModule.cs | 3 ++- 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs b/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs index 703179b184..b87f092a1d 100644 --- a/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs +++ b/src/Umbraco.Tests/Routing/UmbracoModuleTests.cs @@ -23,7 +23,8 @@ namespace Umbraco.Tests.Routing public override void SetUp() { base.SetUp(); - + + // fixme - use the full injected ctor, then we can ditch this one. //create the module _module = new UmbracoModule { diff --git a/src/Umbraco.Web/Editors/DataTypeValidateAttribute.cs b/src/Umbraco.Web/Editors/DataTypeValidateAttribute.cs index f8f2b5ac23..43093f563c 100644 --- a/src/Umbraco.Web/Editors/DataTypeValidateAttribute.cs +++ b/src/Umbraco.Web/Editors/DataTypeValidateAttribute.cs @@ -5,14 +5,15 @@ using System.Net.Http; using System.Web.Http.Controllers; using System.Web.Http.Filters; using AutoMapper; -using LightInject; using Umbraco.Core; +using Umbraco.Core.Composing; using Umbraco.Core.Models; using Umbraco.Core.PropertyEditors; using Umbraco.Core.Services; -using Umbraco.Web.Composing; using Umbraco.Web.Models.ContentEditing; using Umbraco.Web.WebApi; + +using LightInject; namespace Umbraco.Web.Editors { @@ -21,13 +22,25 @@ namespace Umbraco.Web.Editors /// internal sealed class DataTypeValidateAttribute : ActionFilterAttribute { - // LightInject can inject dependencies into properties + public IDataTypeService DataTypeService { get; } - [Inject] - public IDataTypeService DataTypeService { get; set; } + public PropertyEditorCollection PropertyEditors { get; } - [Inject] - public PropertyEditorCollection PropertyEditors { get; set; } + public DataTypeValidateAttribute() + : this(Current.Container.GetInstance(), Current.Container.GetInstance()) + { + } + + /// + /// For use in unit tests. Not possible to use as attribute ctor. + /// + /// + /// + public DataTypeValidateAttribute(IDataTypeService dataTypeService, PropertyEditorCollection propertyEditors) + { + DataTypeService = dataTypeService; + PropertyEditors = propertyEditors; + } public override void OnActionExecuting(HttpActionContext actionContext) { diff --git a/src/Umbraco.Web/UmbracoModule.cs b/src/Umbraco.Web/UmbracoModule.cs index d41ad9ccd0..0efb2a2f85 100644 --- a/src/Umbraco.Web/UmbracoModule.cs +++ b/src/Umbraco.Web/UmbracoModule.cs @@ -93,7 +93,8 @@ namespace Umbraco.Web internal IVariationContextAccessor VariationContextAccessor { get; set; } #endregion - + + // fixme - delete, just one usage in a test. public UmbracoModule() : this( Current.Container.GetInstance(),