UnitOfWork RIP, troubleshoot and fix, tests

This commit is contained in:
Stephan
2017-12-15 16:29:14 +01:00
parent 0ab2f6cc9f
commit bbff74fa51
79 changed files with 501 additions and 588 deletions

View File

@@ -13,14 +13,33 @@ namespace Umbraco.Core.Cache
internal abstract class RepositoryCachePolicyBase<TEntity, TId> : IRepositoryCachePolicy<TEntity, TId>
where TEntity : class, IAggregateRoot
{
protected RepositoryCachePolicyBase(IRuntimeCacheProvider cache)
private readonly IRuntimeCacheProvider _globalCache;
private readonly IScopeAccessor _scopeAccessor;
protected RepositoryCachePolicyBase(IRuntimeCacheProvider globalCache, IScopeAccessor scopeAccessor)
{
Cache = cache ?? throw new ArgumentNullException(nameof(cache));
_globalCache = globalCache ?? throw new ArgumentNullException(nameof(globalCache));
_scopeAccessor = scopeAccessor ?? throw new ArgumentNullException(nameof(scopeAccessor));
}
public abstract IRepositoryCachePolicy<TEntity, TId> Scoped(IRuntimeCacheProvider runtimeCache, IScope scope);
protected IRuntimeCacheProvider Cache { get; }
protected IRuntimeCacheProvider Cache
{
get
{
var ambientScope = _scopeAccessor.AmbientScope;
switch (ambientScope.RepositoryCacheMode)
{
case RepositoryCacheMode.Default:
return _globalCache;
case RepositoryCacheMode.Scoped:
return ambientScope.IsolatedRuntimeCache.GetOrCreateCache<TEntity>();
case RepositoryCacheMode.None:
return NullCacheProvider.Instance;
default:
throw new NotSupportedException($"Repository cache mode {ambientScope.RepositoryCacheMode} is not supported.");
}
}
}
/// <inheritdoc />
public abstract TEntity Get(TId id, Func<TId, TEntity> performGet, Func<TId[], IEnumerable<TEntity>> performGetAll);