Implementations of the new interfaces
This commit is contained in:
@@ -18,14 +18,16 @@ using Umbraco.Extensions;
|
||||
|
||||
namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
|
||||
{
|
||||
internal class MacroRepository : EntityRepositoryBase<int, IMacro>, IMacroRepository
|
||||
internal class MacroRepository : EntityRepositoryBase<int, IMacro>, IMacroWithAliasRepository
|
||||
{
|
||||
private readonly IShortStringHelper _shortStringHelper;
|
||||
private readonly IRepositoryCachePolicy<IMacro, string> _macroByAliasCachePolicy;
|
||||
|
||||
public MacroRepository(IScopeAccessor scopeAccessor, AppCaches cache, ILogger<MacroRepository> logger, IShortStringHelper shortStringHelper)
|
||||
: base(scopeAccessor, cache, logger)
|
||||
{
|
||||
_shortStringHelper = shortStringHelper;
|
||||
_macroByAliasCachePolicy = new DefaultRepositoryCachePolicy<IMacro, string>(GlobalIsolatedCache, ScopeAccessor, DefaultOptions);
|
||||
}
|
||||
|
||||
protected override IMacro PerformGet(int id)
|
||||
@@ -68,6 +70,32 @@ namespace Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement
|
||||
return Get(id) != null;
|
||||
}
|
||||
|
||||
public IMacro GetByAlias(string alias)
|
||||
{
|
||||
return _macroByAliasCachePolicy.Get(alias, PerformGetByAlias, PerformGetAllByAlias);
|
||||
}
|
||||
|
||||
public IEnumerable<IMacro> GetAllByAlias(string[] aliases)
|
||||
{
|
||||
if (aliases.Any() == false) return base.GetMany();
|
||||
|
||||
return _macroByAliasCachePolicy.GetAll(aliases, PerformGetAllByAlias);
|
||||
}
|
||||
|
||||
private IMacro PerformGetByAlias(string alias)
|
||||
{
|
||||
var query = Query<IMacro>().Where(x => x.Alias.Equals(alias));
|
||||
return PerformGetByQuery(query).FirstOrDefault();
|
||||
}
|
||||
|
||||
private IEnumerable<IMacro> PerformGetAllByAlias(params string[] aliases)
|
||||
{
|
||||
if (aliases.Any() == false) return base.GetMany();
|
||||
|
||||
var query = Query<IMacro>().WhereIn(x => x.Alias, aliases);
|
||||
return PerformGetByQuery(query);
|
||||
}
|
||||
|
||||
protected override IEnumerable<IMacro> PerformGetAll(params int[] ids)
|
||||
{
|
||||
return ids.Length > 0 ? ids.Select(Get) : GetAllNoIds();
|
||||
|
||||
@@ -1,31 +1,45 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Umbraco.Cms.Core.Events;
|
||||
using Umbraco.Cms.Core.Models;
|
||||
using Umbraco.Cms.Core.Notifications;
|
||||
using Umbraco.Cms.Core.Persistence.Repositories;
|
||||
using Umbraco.Cms.Core.Scoping;
|
||||
using Umbraco.Cms.Web.Common.DependencyInjection;
|
||||
|
||||
namespace Umbraco.Cms.Core.Services.Implement
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the Macro Service, which is an easy access to operations involving <see cref="IMacro"/>
|
||||
/// </summary>
|
||||
internal class MacroService : RepositoryService, IMacroService
|
||||
internal class MacroService : RepositoryService, IMacroWithAliasService
|
||||
{
|
||||
private readonly IMacroRepository _macroRepository;
|
||||
private readonly IMacroWithAliasRepository _macroRepository;
|
||||
private readonly IAuditRepository _auditRepository;
|
||||
|
||||
public MacroService(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory,
|
||||
IMacroRepository macroRepository, IAuditRepository auditRepository)
|
||||
IMacroWithAliasRepository macroRepository, IAuditRepository auditRepository)
|
||||
: base(provider, loggerFactory, eventMessagesFactory)
|
||||
{
|
||||
_macroRepository = macroRepository;
|
||||
_auditRepository = auditRepository;
|
||||
}
|
||||
|
||||
[Obsolete("Use ctor injecting IMacroWithAliasRepository instead")]
|
||||
public MacroService(IScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory,
|
||||
IMacroRepository macroRepository, IAuditRepository auditRepository)
|
||||
: this (
|
||||
provider,
|
||||
loggerFactory,
|
||||
eventMessagesFactory,
|
||||
StaticServiceProvider.Instance.GetRequiredService<IMacroWithAliasRepository>(),
|
||||
auditRepository)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an <see cref="IMacro"/> object by its alias
|
||||
/// </summary>
|
||||
@@ -35,8 +49,7 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
var q = Query<IMacro>().Where(x => x.Alias == alias);
|
||||
return _macroRepository.Get(q).FirstOrDefault();
|
||||
return _macroRepository.GetByAlias(alias);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,6 +74,14 @@ namespace Umbraco.Cms.Core.Services.Implement
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerable<IMacro> GetAll(params string[] aliases)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
{
|
||||
return _macroRepository.GetAllByAlias(aliases);
|
||||
}
|
||||
}
|
||||
|
||||
public IMacro GetById(int id)
|
||||
{
|
||||
using (var scope = ScopeProvider.CreateScope(autoComplete: true))
|
||||
|
||||
Reference in New Issue
Block a user