Removed circular dependency between data type service and repository, by moving the creation of labels for missing property editors to the service.
This commit is contained in:
@@ -1,25 +1,24 @@
|
||||
using System;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Persistence.Dtos;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
|
||||
|
||||
namespace Umbraco.Core.Persistence.Factories
|
||||
{
|
||||
internal static class DataTypeFactory
|
||||
{
|
||||
public static IDataType BuildEntity(DataTypeDto dto, PropertyEditorCollection editors, ILogger logger, IIOHelper ioHelper, IDataTypeService dataTypeService, ILocalizedTextService localizedTextService, ILocalizationService localizationService, IShortStringHelper shortStringHelper)
|
||||
public static IDataType BuildEntity(DataTypeDto dto, PropertyEditorCollection editors, ILogger logger)
|
||||
{
|
||||
// Check we have an editor for the data type.
|
||||
if (!editors.TryGet(dto.EditorAlias, out var editor))
|
||||
{
|
||||
logger.Warn(typeof(DataType), "Could not find an editor with alias {EditorAlias}, treating as Label."
|
||||
+" The site may fail to boot and / or load data types and run.", dto.EditorAlias);
|
||||
//convert to label
|
||||
editor = new LabelPropertyEditor(logger, ioHelper,dataTypeService , localizedTextService, localizationService, shortStringHelper);
|
||||
logger.Warn(typeof(DataType), "Could not find an editor with alias {EditorAlias}, treating as Label. " +
|
||||
"The site may fail to boot and/or load data types and run.", dto.EditorAlias);
|
||||
|
||||
// Create as special type, which downstream can be handled by converting to a LabelPropertyEditor to make clear
|
||||
// the situation to the user.
|
||||
editor = new MissingPropertyEditor();
|
||||
}
|
||||
|
||||
var dataType = new DataType(editor);
|
||||
|
||||
@@ -7,7 +7,6 @@ using NPoco;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Events;
|
||||
using Umbraco.Core.Exceptions;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Models;
|
||||
using Umbraco.Core.Models.Entities;
|
||||
@@ -17,7 +16,6 @@ using Umbraco.Core.Persistence.Querying;
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
using Umbraco.Core.Scoping;
|
||||
using Umbraco.Core.Services;
|
||||
using Umbraco.Core.Strings;
|
||||
using static Umbraco.Core.Persistence.SqlExtensionsStatics;
|
||||
|
||||
namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
@@ -28,22 +26,11 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
internal class DataTypeRepository : NPocoRepositoryBase<int, IDataType>, IDataTypeRepository
|
||||
{
|
||||
private readonly Lazy<PropertyEditorCollection> _editors;
|
||||
private readonly IIOHelper _ioHelper;
|
||||
private readonly Lazy<IDataTypeService> _dataTypeService;
|
||||
private readonly ILocalizedTextService _localizedTextService;
|
||||
private readonly ILocalizationService _localizationService;
|
||||
private readonly IShortStringHelper _shortStringHelper;
|
||||
|
||||
// TODO: https://github.com/umbraco/Umbraco-CMS/issues/4237 - get rid of Lazy injection and fix circular dependencies
|
||||
public DataTypeRepository(IScopeAccessor scopeAccessor, AppCaches cache, Lazy<PropertyEditorCollection> editors, ILogger logger, IIOHelper ioHelper, Lazy<IDataTypeService> dataTypeService, ILocalizedTextService localizedTextService, ILocalizationService localizationService, IShortStringHelper shortStringHelper)
|
||||
public DataTypeRepository(IScopeAccessor scopeAccessor, AppCaches cache, Lazy<PropertyEditorCollection> editors, ILogger logger)
|
||||
: base(scopeAccessor, cache, logger)
|
||||
{
|
||||
_editors = editors;
|
||||
_ioHelper = ioHelper;
|
||||
_dataTypeService = dataTypeService;
|
||||
_localizedTextService = localizedTextService;
|
||||
_localizationService = localizationService;
|
||||
_shortStringHelper = shortStringHelper;
|
||||
}
|
||||
|
||||
#region Overrides of RepositoryBase<int,DataTypeDefinition>
|
||||
@@ -67,7 +54,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
}
|
||||
|
||||
var dtos = Database.Fetch<DataTypeDto>(dataTypeSql);
|
||||
return dtos.Select(x => DataTypeFactory.BuildEntity(x, _editors.Value, Logger,_ioHelper, _dataTypeService.Value, _localizedTextService, _localizationService, _shortStringHelper)).ToArray();
|
||||
return dtos.Select(x => DataTypeFactory.BuildEntity(x, _editors.Value, Logger)).ToArray();
|
||||
}
|
||||
|
||||
protected override IEnumerable<IDataType> PerformGetByQuery(IQuery<IDataType> query)
|
||||
@@ -78,7 +65,7 @@ namespace Umbraco.Core.Persistence.Repositories.Implement
|
||||
|
||||
var dtos = Database.Fetch<DataTypeDto>(sql);
|
||||
|
||||
return dtos.Select(x => DataTypeFactory.BuildEntity(x, _editors.Value, Logger, _ioHelper, _dataTypeService.Value, _localizedTextService, _localizationService, _shortStringHelper)).ToArray();
|
||||
return dtos.Select(x => DataTypeFactory.BuildEntity(x, _editors.Value, Logger)).ToArray();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user