Merge pull request #7496 from benjaminc/netcore/feature/7369-remove-current-services

Replace Current.Services references with DI where possible
This commit is contained in:
Bjarke Berg
2020-01-23 13:39:59 +01:00
committed by GitHub
12 changed files with 47 additions and 32 deletions
@@ -152,7 +152,7 @@ namespace Umbraco.Tests.Routing
var handler = new RenderRouteHandler(umbracoContext, new TestControllerFactory(umbracoContextAccessor, Mock.Of<ILogger>(), context =>
{
var membershipHelper = new MembershipHelper(
umbracoContext.HttpContext, Mock.Of<IPublishedMemberCache>(), Mock.Of<MembersMembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IPublicAccessService>(), AppCaches.Disabled, Mock.Of<ILogger>(), ShortStringHelper);
umbracoContext.HttpContext, Mock.Of<IPublishedMemberCache>(), Mock.Of<MembersMembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IPublicAccessService>(), AppCaches.Disabled, Mock.Of<ILogger>(), ShortStringHelper, Mock.Of<IEntityService>());
return new CustomDocumentController(Factory.GetInstance<IGlobalSettings>(),
umbracoContextAccessor,
Factory.GetInstance<ServiceContext>(),
@@ -153,7 +153,7 @@ namespace Umbraco.Tests.TestHelpers.ControllerTesting
urlHelper.Setup(provider => provider.GetUrl(It.IsAny<UmbracoContext>(), It.IsAny<IPublishedContent>(), It.IsAny<UrlMode>(), It.IsAny<string>(), It.IsAny<Uri>()))
.Returns(UrlInfo.Url("/hello/world/1234"));
var membershipHelper = new MembershipHelper(umbCtx.HttpContext, Mock.Of<IPublishedMemberCache>(), Mock.Of<MembersMembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IPublicAccessService>(), AppCaches.Disabled, Mock.Of<ILogger>(), new MockShortStringHelper());
var membershipHelper = new MembershipHelper(umbCtx.HttpContext, Mock.Of<IPublishedMemberCache>(), Mock.Of<MembersMembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IPublicAccessService>(), AppCaches.Disabled, Mock.Of<ILogger>(), new MockShortStringHelper(), Mock.Of<IEntityService>());
var umbHelper = new UmbracoHelper(Mock.Of<IPublishedContent>(),
Mock.Of<ITagQuery>(),
@@ -71,7 +71,7 @@ namespace Umbraco.Tests.Testing.TestingTests
Mock.Of<ICultureDictionaryFactory>(),
Mock.Of<IUmbracoComponentRenderer>(),
Mock.Of<IPublishedContentQuery>(),
new MembershipHelper(umbracoContext.HttpContext, Mock.Of<IPublishedMemberCache>(), Mock.Of<MembersMembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IPublicAccessService>(), AppCaches.Disabled, Mock.Of<ILogger>(), ShortStringHelper));
new MembershipHelper(umbracoContext.HttpContext, Mock.Of<IPublishedMemberCache>(), Mock.Of<MembersMembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IPublicAccessService>(), AppCaches.Disabled, Mock.Of<ILogger>(), ShortStringHelper, Mock.Of<IEntityService>()));
Assert.Pass();
}
@@ -103,7 +103,7 @@ namespace Umbraco.Tests.Testing.TestingTests
var memberService = Mock.Of<IMemberService>();
var memberTypeService = Mock.Of<IMemberTypeService>();
var membershipProvider = new MembersMembershipProvider(memberService, memberTypeService, Mock.Of<IUmbracoVersion>(), TestHelper.GetHostingEnvironment(), TestHelper.GetIpResolver());
var membershipHelper = new MembershipHelper(umbracoContext.HttpContext, Mock.Of<IPublishedMemberCache>(), membershipProvider, Mock.Of<RoleProvider>(), memberService, memberTypeService, Mock.Of<IPublicAccessService>(), AppCaches.Disabled, logger, ShortStringHelper);
var membershipHelper = new MembershipHelper(umbracoContext.HttpContext, Mock.Of<IPublishedMemberCache>(), membershipProvider, Mock.Of<RoleProvider>(), memberService, memberTypeService, Mock.Of<IPublicAccessService>(), AppCaches.Disabled, logger, ShortStringHelper, Mock.Of<IEntityService>());
var umbracoHelper = new UmbracoHelper(Mock.Of<IPublishedContent>(), Mock.Of<ITagQuery>(), Mock.Of<ICultureDictionaryFactory>(), Mock.Of<IUmbracoComponentRenderer>(), Mock.Of<IPublishedContentQuery>(), membershipHelper);
var umbracoMapper = new UmbracoMapper(new MapDefinitionCollection(new[] { Mock.Of<IMapDefinition>() }));
@@ -124,7 +124,7 @@ namespace Umbraco.Tests.Web.Mvc
Mock.Of<ICultureDictionaryFactory>(),
Mock.Of<IUmbracoComponentRenderer>(),
Mock.Of<IPublishedContentQuery>(query => query.Content(2) == content.Object),
new MembershipHelper(umbracoContext.HttpContext, Mock.Of<IPublishedMemberCache>(), Mock.Of<MembersMembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IPublicAccessService>(), AppCaches.Disabled, Mock.Of<ILogger>(), ShortStringHelper));
new MembershipHelper(umbracoContext.HttpContext, Mock.Of<IPublishedMemberCache>(), Mock.Of<MembersMembershipProvider>(), Mock.Of<RoleProvider>(), Mock.Of<IMemberService>(), Mock.Of<IMemberTypeService>(), Mock.Of<IPublicAccessService>(), AppCaches.Disabled, Mock.Of<ILogger>(), ShortStringHelper, Mock.Of<IEntityService>()));
var ctrl = new TestSurfaceController(umbracoContextAccessor, helper);
var result = ctrl.GetContent(2) as PublishedContentResult;
@@ -1,4 +1,5 @@
using Umbraco.Core;
using System;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Services;
using Umbraco.Core.Services.Implement;
@@ -8,15 +9,21 @@ namespace Umbraco.Web.Compose
{
public sealed class PublicAccessComponent : IComponent
{
private readonly IPublicAccessService _publicAccessService;
public PublicAccessComponent(IPublicAccessService publicAccessService)
{
_publicAccessService = publicAccessService ?? throw new ArgumentNullException(nameof(publicAccessService));
}
public void Initialize()
{
MemberGroupService.Saved += MemberGroupService_Saved;
MemberGroupService.Saved += (s, e) => MemberGroupService_Saved(s, e, _publicAccessService);
}
public void Terminate()
{ }
static void MemberGroupService_Saved(IMemberGroupService sender, Core.Events.SaveEventArgs<Core.Models.IMemberGroup> e)
static void MemberGroupService_Saved(IMemberGroupService sender, Core.Events.SaveEventArgs<Core.Models.IMemberGroup> e, IPublicAccessService publicAccessService)
{
foreach (var grp in e.SavedEntities)
{
@@ -26,7 +33,7 @@ namespace Umbraco.Web.Compose
&& grp.AdditionalData["previousName"].ToString().IsNullOrWhiteSpace() == false
&& grp.AdditionalData["previousName"].ToString() != grp.Name)
{
Current.Services.PublicAccessService.RenameMemberGroupRoleRules(grp.AdditionalData["previousName"].ToString(), grp.Name);
publicAccessService.RenameMemberGroupRoleRules(grp.AdditionalData["previousName"].ToString(), grp.Name);
}
}
}
@@ -39,11 +39,13 @@ namespace Umbraco.Web.Editors
public class MediaTypeController : ContentTypeControllerBase<IMediaType>
{
private readonly IShortStringHelper _shortStringHelper;
private readonly IEntityService _entityService;
public MediaTypeController(ICultureDictionary cultureDictionary, IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoHelper umbracoHelper, IShortStringHelper shortStringHelper, UmbracoMapper umbracoMapper)
public MediaTypeController(ICultureDictionary cultureDictionary, IGlobalSettings globalSettings, IUmbracoContextAccessor umbracoContextAccessor, ISqlContext sqlContext, ServiceContext services, AppCaches appCaches, IProfilingLogger logger, IRuntimeState runtimeState, UmbracoHelper umbracoHelper, IShortStringHelper shortStringHelper, UmbracoMapper umbracoMapper, IEntityService entityService)
: base(cultureDictionary, globalSettings, umbracoContextAccessor, sqlContext, services, appCaches, logger, runtimeState, umbracoHelper, shortStringHelper, umbracoMapper)
{
_shortStringHelper = shortStringHelper;
_entityService = entityService ?? throw new ArgumentNullException(nameof(entityService));
}
/// <summary>
@@ -270,7 +272,7 @@ namespace Umbraco.Web.Editors
[UmbracoTreeAuthorize(Constants.Trees.MediaTypes, Constants.Trees.Media)]
public IEnumerable<ContentTypeBasic> GetAllowedChildren(Guid contentId)
{
var entity = Current.Services.EntityService.Get(contentId);
var entity = _entityService.Get(contentId);
if (entity != null)
{
return GetAllowedChildren(entity.Id);
@@ -289,7 +291,7 @@ namespace Umbraco.Web.Editors
var guidUdi = contentId as GuidUdi;
if (guidUdi != null)
{
var entity = Current.Services.EntityService.Get(guidUdi.Guid);
var entity = _entityService.Get(guidUdi.Guid);
if (entity != null)
{
return GetAllowedChildren(entity.Id);
@@ -77,8 +77,8 @@ namespace Umbraco.Web.Macros
/// <param name="content">The content.</param>
/// <param name="variationContextAccessor"></param>
/// <remarks>This is for <see cref="MacroRenderingController"/> usage only.</remarks>
internal PublishedContentHashtableConverter(IContent content, IVariationContextAccessor variationContextAccessor, IUserService userService, IShortStringHelper shortStringHelper)
: this(new PagePublishedContent(content, variationContextAccessor, userService, shortStringHelper))
internal PublishedContentHashtableConverter(IContent content, IVariationContextAccessor variationContextAccessor, IUserService userService, IShortStringHelper shortStringHelper, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IPublishedContentTypeFactory publishedContentTypeFactory, UrlSegmentProviderCollection urlSegmentProviders)
: this(new PagePublishedContent(content, variationContextAccessor, userService, shortStringHelper, contentTypeBaseServiceProvider, publishedContentTypeFactory, urlSegmentProviders))
{ }
#endregion
@@ -186,6 +186,7 @@ namespace Umbraco.Web.Macros
private IReadOnlyDictionary<string, PublishedCultureInfo> _cultureInfos;
private readonly IVariationContextAccessor _variationContextAccessor;
private readonly IShortStringHelper _shortStringHelper;
private readonly UrlSegmentProviderCollection _urlSegmentProviders;
private static readonly IReadOnlyDictionary<string, PublishedCultureInfo> NoCultureInfos = new Dictionary<string, PublishedCultureInfo>();
@@ -194,11 +195,12 @@ namespace Umbraco.Web.Macros
Id = id;
}
public PagePublishedContent(IContent inner, IVariationContextAccessor variationContextAccessor, IUserService userService, IShortStringHelper shortStringHelper)
public PagePublishedContent(IContent inner, IVariationContextAccessor variationContextAccessor, IUserService userService, IShortStringHelper shortStringHelper, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, IPublishedContentTypeFactory publishedContentTypeFactory, UrlSegmentProviderCollection urlSegmentProviders)
{
_inner = inner ?? throw new ArgumentNullException(nameof(inner));
_variationContextAccessor = variationContextAccessor;
_shortStringHelper = shortStringHelper ?? throw new ArgumentNullException(nameof(shortStringHelper));
_urlSegmentProviders = urlSegmentProviders ?? throw new ArgumentNullException(nameof(urlSegmentProviders));
Id = _inner.Id;
Key = _inner.Key;
@@ -206,9 +208,8 @@ namespace Umbraco.Web.Macros
CreatorName = _inner.GetCreatorProfile(userService)?.Name;
WriterName = _inner.GetWriterProfile(userService)?.Name;
// TODO: inject
var contentType = Current.Services.ContentTypeBaseServices.GetContentTypeOf(_inner);
ContentType = Current.PublishedContentTypeFactory.CreateContentType(contentType);
var contentType = contentTypeBaseServiceProvider.GetContentTypeOf(_inner);
ContentType = publishedContentTypeFactory.CreateContentType(contentType);
_properties = ContentType.PropertyTypes
.Select(x =>
@@ -244,9 +245,8 @@ namespace Umbraco.Web.Macros
if (_cultureInfos != null)
return _cultureInfos;
var urlSegmentProviders = Current.UrlSegmentProviders; // TODO inject
return _cultureInfos = _inner.PublishCultureInfos.Values
.ToDictionary(x => x.Culture, x => new PublishedCultureInfo(x.Culture, x.Name, _inner.GetUrlSegment(_shortStringHelper, urlSegmentProviders, x.Culture), x.Date));
.ToDictionary(x => x.Culture, x => new PublishedCultureInfo(x.Culture, x.Name, _inner.GetUrlSegment(_shortStringHelper, _urlSegmentProviders, x.Culture), x.Date));
}
}
@@ -38,7 +38,7 @@ namespace Umbraco.Web.Models.Mapping
public ContentMapDefinition(CommonMapper commonMapper, ICultureDictionary cultureDictionary, ILocalizedTextService localizedTextService, IContentService contentService, IContentTypeService contentTypeService,
IFileService fileService, IUmbracoContextAccessor umbracoContextAccessor, IPublishedRouter publishedRouter, ILocalizationService localizationService, ILogger logger,
IUserService userService, IVariationContextAccessor variationContextAccessor)
IUserService userService, IVariationContextAccessor variationContextAccessor, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider)
{
_commonMapper = commonMapper;
_cultureDictionary = cultureDictionary;
@@ -53,7 +53,7 @@ namespace Umbraco.Web.Models.Mapping
_userService = userService;
_variationContextAccessor = variationContextAccessor;
_tabsAndPropertiesMapper = new TabsAndPropertiesMapper<IContent>(cultureDictionary, localizedTextService);
_tabsAndPropertiesMapper = new TabsAndPropertiesMapper<IContent>(cultureDictionary, localizedTextService, contentTypeBaseServiceProvider);
_stateMapper = new ContentSavedStateMapper<ContentPropertyDisplay>();
_basicStateMapper = new ContentBasicSavedStateMapper<ContentPropertyBasic>();
_contentVariantMapper = new ContentVariantMapper(_localizationService);
@@ -26,7 +26,7 @@ namespace Umbraco.Web.Models.Mapping
private readonly IUmbracoSettingsSection _umbracoSettingsSection;
public MediaMapDefinition(ICultureDictionary cultureDictionary, ILogger logger, CommonMapper commonMapper, IMediaService mediaService, IMediaTypeService mediaTypeService,
ILocalizedTextService localizedTextService, PropertyEditorCollection propertyEditorCollection, IUmbracoSettingsSection umbracoSettingsSection)
ILocalizedTextService localizedTextService, PropertyEditorCollection propertyEditorCollection, IUmbracoSettingsSection umbracoSettingsSection, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider)
{
_logger = logger;
_commonMapper = commonMapper;
@@ -35,7 +35,7 @@ namespace Umbraco.Web.Models.Mapping
_propertyEditorCollection = propertyEditorCollection;
_umbracoSettingsSection = umbracoSettingsSection ?? throw new ArgumentNullException(nameof(umbracoSettingsSection));
_tabsAndPropertiesMapper = new TabsAndPropertiesMapper<IMedia>(cultureDictionary, localizedTextService);
_tabsAndPropertiesMapper = new TabsAndPropertiesMapper<IMedia>(cultureDictionary, localizedTextService, contentTypeBaseServiceProvider);
}
public void DefineMaps(UmbracoMapper mapper)
@@ -29,8 +29,8 @@ namespace Umbraco.Web.Models.Mapping
private readonly IMemberGroupService _memberGroupService;
private readonly IMemberPasswordConfiguration _memberPasswordConfiguration;
public MemberTabsAndPropertiesMapper(ICultureDictionary cultureDictionary, IUmbracoContextAccessor umbracoContextAccessor, ILocalizedTextService localizedTextService, IMemberTypeService memberTypeService, IMemberService memberService, IMemberGroupService memberGroupService, IMemberPasswordConfiguration memberPasswordConfiguration)
: base(cultureDictionary, localizedTextService)
public MemberTabsAndPropertiesMapper(ICultureDictionary cultureDictionary, IUmbracoContextAccessor umbracoContextAccessor, ILocalizedTextService localizedTextService, IMemberTypeService memberTypeService, IMemberService memberService, IMemberGroupService memberGroupService, IMemberPasswordConfiguration memberPasswordConfiguration, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider)
: base(cultureDictionary, localizedTextService, contentTypeBaseServiceProvider)
{
_umbracoContextAccessor = umbracoContextAccessor ?? throw new ArgumentNullException(nameof(umbracoContextAccessor));
_localizedTextService = localizedTextService ?? throw new ArgumentNullException(nameof(localizedTextService));
@@ -118,15 +118,19 @@ namespace Umbraco.Web.Models.Mapping
internal class TabsAndPropertiesMapper<TSource> : TabsAndPropertiesMapper
where TSource : IContentBase
{
public TabsAndPropertiesMapper(ICultureDictionary cultureDictionary, ILocalizedTextService localizedTextService)
private readonly IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider;
public TabsAndPropertiesMapper(ICultureDictionary cultureDictionary, ILocalizedTextService localizedTextService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider)
: base(cultureDictionary, localizedTextService)
{ }
{
_contentTypeBaseServiceProvider = contentTypeBaseServiceProvider ?? throw new ArgumentNullException(nameof(contentTypeBaseServiceProvider));
}
public virtual IEnumerable<Tab<ContentPropertyDisplay>> Map(TSource source, MapperContext context)
{
var tabs = new List<Tab<ContentPropertyDisplay>>();
var contentType = Current.Services.ContentTypeBaseServices.GetContentTypeOf(source);
var contentType = _contentTypeBaseServiceProvider.GetContentTypeOf(source);
// add the tabs, for properties that belong to a tab
// need to aggregate the tabs, as content.PropertyGroups contains all the composition tabs,
+5 -3
View File
@@ -33,6 +33,7 @@ namespace Umbraco.Web.Security
private readonly AppCaches _appCaches;
private readonly ILogger _logger;
private readonly IShortStringHelper _shortStringHelper;
private readonly IEntityService _entityService;
#region Constructors
@@ -47,7 +48,8 @@ namespace Umbraco.Web.Security
IPublicAccessService publicAccessService,
AppCaches appCaches,
ILogger logger,
IShortStringHelper shortStringHelper
IShortStringHelper shortStringHelper,
IEntityService entityService
)
{
HttpContext = httpContext;
@@ -61,6 +63,7 @@ namespace Umbraco.Web.Security
_membershipProvider = membershipProvider ?? throw new ArgumentNullException(nameof(membershipProvider));
_roleProvider = roleProvider ?? throw new ArgumentNullException(nameof(roleProvider));
_entityService = entityService ?? throw new ArgumentNullException(nameof(entityService));
}
#endregion
@@ -311,12 +314,11 @@ namespace Umbraco.Web.Security
var umbracoType = UdiEntityTypeHelper.ToUmbracoObjectType(udi.EntityType);
var entityService = Current.Services.EntityService;
switch (umbracoType)
{
case UmbracoObjectTypes.Member:
// TODO: need to implement Get(guid)!
var memberAttempt = entityService.GetId(guidUdi.Guid, umbracoType);
var memberAttempt = _entityService.GetId(guidUdi.Guid, umbracoType);
if (memberAttempt.Success)
return GetById(memberAttempt.Result);
break;