Use dependency injection for config classes

This commit is contained in:
Benjamin Carleski
2020-01-21 17:03:46 -08:00
parent 1bf1a86f94
commit fd3ef48367
42 changed files with 230 additions and 126 deletions

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using Umbraco.Core;
using Umbraco.Core.Configuration.UmbracoSettings;
using Umbraco.Core.Logging;
using Umbraco.Core.Mapping;
using Umbraco.Core.Models;
@@ -15,11 +16,13 @@ namespace Umbraco.Web.Models.Mapping
{
private readonly PropertyEditorCollection _propertyEditors;
private readonly ILogger _logger;
private readonly IUmbracoSettingsSection _umbracoSettingsSection;
public DataTypeMapDefinition(PropertyEditorCollection propertyEditors, ILogger logger)
public DataTypeMapDefinition(PropertyEditorCollection propertyEditors, ILogger logger, IUmbracoSettingsSection umbracoSettingsSection)
{
_propertyEditors = propertyEditors;
_logger = logger;
_umbracoSettingsSection = umbracoSettingsSection ?? throw new ArgumentNullException(nameof(umbracoSettingsSection));
}
private static readonly int[] SystemIds =
@@ -126,7 +129,7 @@ namespace Umbraco.Web.Models.Mapping
private IEnumerable<PropertyEditorBasic> MapAvailableEditors(IDataType source, MapperContext context)
{
var contentSection = Current.Configs.Settings().Content;
var contentSection = _umbracoSettingsSection.Content;
var properties = _propertyEditors
.Where(x => !x.IsDeprecated || contentSection.ShowDeprecatedPropertyEditors || source.EditorAlias == x.Alias)
.OrderBy(x => x.Name);

View File

@@ -1,5 +1,4 @@
using Umbraco.Core;
using Umbraco.Web.Composing;
using Umbraco.Core.Dictionary;
using Umbraco.Core.Logging;
using Umbraco.Core.Mapping;
@@ -8,6 +7,8 @@ using Umbraco.Core.PropertyEditors;
using Umbraco.Core.Services;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Web.Trees;
using Umbraco.Core.Configuration.UmbracoSettings;
using System;
namespace Umbraco.Web.Models.Mapping
{
@@ -22,15 +23,17 @@ namespace Umbraco.Web.Models.Mapping
private readonly IMediaTypeService _mediaTypeService;
private readonly PropertyEditorCollection _propertyEditorCollection;
private readonly TabsAndPropertiesMapper<IMedia> _tabsAndPropertiesMapper;
private readonly IUmbracoSettingsSection _umbracoSettingsSection;
public MediaMapDefinition(ICultureDictionary cultureDictionary, ILogger logger, CommonMapper commonMapper, IMediaService mediaService, IMediaTypeService mediaTypeService,
ILocalizedTextService localizedTextService, PropertyEditorCollection propertyEditorCollection)
ILocalizedTextService localizedTextService, PropertyEditorCollection propertyEditorCollection, IUmbracoSettingsSection umbracoSettingsSection)
{
_logger = logger;
_commonMapper = commonMapper;
_mediaService = mediaService;
_mediaTypeService = mediaTypeService;
_propertyEditorCollection = propertyEditorCollection;
_umbracoSettingsSection = umbracoSettingsSection ?? throw new ArgumentNullException(nameof(umbracoSettingsSection));
_tabsAndPropertiesMapper = new TabsAndPropertiesMapper<IMedia>(cultureDictionary, localizedTextService);
}
@@ -61,7 +64,7 @@ namespace Umbraco.Web.Models.Mapping
target.Id = source.Id;
target.IsChildOfListView = DermineIsChildOfListView(source);
target.Key = source.Key;
target.MediaLink = string.Join(",", source.GetUrls(Current.Configs.Settings().Content, _logger, _propertyEditorCollection));
target.MediaLink = string.Join(",", source.GetUrls(_umbracoSettingsSection.Content, _logger, _propertyEditorCollection));
target.Name = source.Name;
target.Owner = _commonMapper.GetOwner(source, context);
target.ParentId = source.ParentId;