Updated all repo's to have their correct ctor's with their correct dependencies. Updated them all to accept ILogger updated all other dependencies with the same without breaking anything since all is internal, or obsoleted other public methods. Updates lots of the tests with mock instances instead, now more tests have less singleton dependencies, easier to test, much clearer and more IoC driven. Updated unit tests to supply the ILogger for required objects, tests should run faster now since most things are just mocked.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using Umbraco.Core.Configuration;
|
||||
using System;
|
||||
using Umbraco.Core.Configuration.UmbracoSettings;
|
||||
using Umbraco.Core.IO;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Core.Persistence.Caching;
|
||||
using Umbraco.Core.Persistence.Repositories;
|
||||
using Umbraco.Core.Persistence.UnitOfWork;
|
||||
@@ -13,56 +15,71 @@ namespace Umbraco.Core.Persistence
|
||||
public class RepositoryFactory
|
||||
{
|
||||
private readonly bool _disableAllCache;
|
||||
private readonly ILogger _logger;
|
||||
private readonly CacheHelper _cacheHelper;
|
||||
private readonly IUmbracoSettingsSection _settings;
|
||||
|
||||
#region Ctors
|
||||
|
||||
public RepositoryFactory(CacheHelper cacheHelper, ILogger logger, IUmbracoSettingsSection settings)
|
||||
{
|
||||
if (cacheHelper == null) throw new ArgumentNullException("cacheHelper");
|
||||
if (logger == null) throw new ArgumentNullException("logger");
|
||||
if (settings == null) throw new ArgumentNullException("settings");
|
||||
_disableAllCache = false;
|
||||
_cacheHelper = cacheHelper;
|
||||
_logger = logger;
|
||||
_settings = settings;
|
||||
}
|
||||
|
||||
public RepositoryFactory(bool disableAllCache, ILogger logger, IUmbracoSettingsSection settings)
|
||||
{
|
||||
if (logger == null) throw new ArgumentNullException("logger");
|
||||
if (settings == null) throw new ArgumentNullException("settings");
|
||||
_disableAllCache = disableAllCache;
|
||||
_logger = logger;
|
||||
_settings = settings;
|
||||
_cacheHelper = _disableAllCache ? CacheHelper.CreateDisabledCacheHelper() : ApplicationContext.Current.ApplicationCache;
|
||||
}
|
||||
|
||||
[Obsolete("Use the ctor specifying all dependencies instead")]
|
||||
public RepositoryFactory()
|
||||
: this(false, UmbracoConfig.For.UmbracoSettings())
|
||||
: this(false, LoggerResolver.Current.Logger, UmbracoConfig.For.UmbracoSettings())
|
||||
{
|
||||
}
|
||||
|
||||
[Obsolete("Use the ctor specifying an ILogger instead")]
|
||||
public RepositoryFactory(CacheHelper cacheHelper)
|
||||
: this(false, UmbracoConfig.For.UmbracoSettings())
|
||||
: this(false, LoggerResolver.Current.Logger, UmbracoConfig.For.UmbracoSettings())
|
||||
{
|
||||
if (cacheHelper == null) throw new ArgumentNullException("cacheHelper");
|
||||
_disableAllCache = false;
|
||||
_cacheHelper = cacheHelper;
|
||||
}
|
||||
|
||||
[Obsolete("Use the ctor specifying an ILogger instead")]
|
||||
public RepositoryFactory(bool disableAllCache, CacheHelper cacheHelper)
|
||||
: this(disableAllCache, UmbracoConfig.For.UmbracoSettings())
|
||||
: this(disableAllCache, LoggerResolver.Current.Logger, UmbracoConfig.For.UmbracoSettings())
|
||||
{
|
||||
if (cacheHelper == null) throw new ArgumentNullException("cacheHelper");
|
||||
_cacheHelper = cacheHelper;
|
||||
}
|
||||
|
||||
[Obsolete("Use the ctor specifying an ILogger instead")]
|
||||
public RepositoryFactory(bool disableAllCache)
|
||||
: this(disableAllCache, UmbracoConfig.For.UmbracoSettings())
|
||||
: this(disableAllCache, LoggerResolver.Current.Logger, UmbracoConfig.For.UmbracoSettings())
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal RepositoryFactory(bool disableAllCache, IUmbracoSettingsSection settings)
|
||||
{
|
||||
_disableAllCache = disableAllCache;
|
||||
_settings = settings;
|
||||
_cacheHelper = _disableAllCache ? CacheHelper.CreateDisabledCacheHelper() : ApplicationContext.Current.ApplicationCache;
|
||||
}
|
||||
|
||||
internal RepositoryFactory(bool disableAllCache, IUmbracoSettingsSection settings, CacheHelper cacheHelper)
|
||||
{
|
||||
_disableAllCache = disableAllCache;
|
||||
_settings = settings;
|
||||
_cacheHelper = cacheHelper;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public virtual ITagRepository CreateTagRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return new TagRepository(
|
||||
uow,
|
||||
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current);
|
||||
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current, _logger);
|
||||
}
|
||||
|
||||
public virtual IContentRepository CreateContentRepository(IDatabaseUnitOfWork uow)
|
||||
@@ -70,6 +87,7 @@ namespace Umbraco.Core.Persistence
|
||||
return new ContentRepository(
|
||||
uow,
|
||||
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current,
|
||||
_logger,
|
||||
CreateContentTypeRepository(uow),
|
||||
CreateTemplateRepository(uow),
|
||||
CreateTagRepository(uow),
|
||||
@@ -81,6 +99,7 @@ namespace Umbraco.Core.Persistence
|
||||
return new ContentTypeRepository(
|
||||
uow,
|
||||
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current,
|
||||
_logger,
|
||||
CreateTemplateRepository(uow));
|
||||
}
|
||||
|
||||
@@ -88,8 +107,9 @@ namespace Umbraco.Core.Persistence
|
||||
{
|
||||
return new DataTypeDefinitionRepository(
|
||||
uow,
|
||||
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current,
|
||||
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current,
|
||||
_cacheHelper,
|
||||
_logger,
|
||||
CreateContentTypeRepository(uow));
|
||||
}
|
||||
|
||||
@@ -98,6 +118,7 @@ namespace Umbraco.Core.Persistence
|
||||
return new DictionaryRepository(
|
||||
uow,
|
||||
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current,
|
||||
_logger,
|
||||
CreateLanguageRepository(uow));
|
||||
}
|
||||
|
||||
@@ -105,7 +126,8 @@ namespace Umbraco.Core.Persistence
|
||||
{
|
||||
return new LanguageRepository(
|
||||
uow,
|
||||
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current);
|
||||
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current,
|
||||
_logger);
|
||||
}
|
||||
|
||||
public virtual IMediaRepository CreateMediaRepository(IDatabaseUnitOfWork uow)
|
||||
@@ -113,6 +135,7 @@ namespace Umbraco.Core.Persistence
|
||||
return new MediaRepository(
|
||||
uow,
|
||||
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current,
|
||||
_logger,
|
||||
CreateMediaTypeRepository(uow),
|
||||
CreateTagRepository(uow)) { EnsureUniqueNaming = _settings.Content.EnsureUniqueNaming };
|
||||
}
|
||||
@@ -121,7 +144,8 @@ namespace Umbraco.Core.Persistence
|
||||
{
|
||||
return new MediaTypeRepository(
|
||||
uow,
|
||||
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current);
|
||||
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current,
|
||||
_logger);
|
||||
}
|
||||
|
||||
public virtual IRelationRepository CreateRelationRepository(IDatabaseUnitOfWork uow)
|
||||
@@ -129,6 +153,7 @@ namespace Umbraco.Core.Persistence
|
||||
return new RelationRepository(
|
||||
uow,
|
||||
NullCacheProvider.Current,
|
||||
_logger,
|
||||
CreateRelationTypeRepository(uow));
|
||||
}
|
||||
|
||||
@@ -136,7 +161,8 @@ namespace Umbraco.Core.Persistence
|
||||
{
|
||||
return new RelationTypeRepository(
|
||||
uow,
|
||||
NullCacheProvider.Current);
|
||||
NullCacheProvider.Current,
|
||||
_logger);
|
||||
}
|
||||
|
||||
public virtual IScriptRepository CreateScriptRepository(IUnitOfWork uow)
|
||||
@@ -161,14 +187,20 @@ namespace Umbraco.Core.Persistence
|
||||
|
||||
public virtual ITemplateRepository CreateTemplateRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return new TemplateRepository(uow, _disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current);
|
||||
return new TemplateRepository(uow,
|
||||
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current,
|
||||
_logger,
|
||||
new PhysicalFileSystem(SystemDirectories.Masterpages),
|
||||
new PhysicalFileSystem(SystemDirectories.MvcViews),
|
||||
_settings.Templates);
|
||||
}
|
||||
|
||||
internal virtual ServerRegistrationRepository CreateServerRegistrationRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return new ServerRegistrationRepository(
|
||||
uow,
|
||||
NullCacheProvider.Current);
|
||||
NullCacheProvider.Current,
|
||||
_logger);
|
||||
}
|
||||
|
||||
public virtual IUserTypeRepository CreateUserTypeRepository(IDatabaseUnitOfWork uow)
|
||||
@@ -176,7 +208,8 @@ namespace Umbraco.Core.Persistence
|
||||
return new UserTypeRepository(
|
||||
uow,
|
||||
//There's not many user types but we query on users all the time so the result needs to be cached
|
||||
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current);
|
||||
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current,
|
||||
_logger);
|
||||
}
|
||||
|
||||
public virtual IUserRepository CreateUserRepository(IDatabaseUnitOfWork uow)
|
||||
@@ -185,13 +218,16 @@ namespace Umbraco.Core.Persistence
|
||||
uow,
|
||||
//Need to cache users - we look up user information more than anything in the back office!
|
||||
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current,
|
||||
_logger,
|
||||
CreateUserTypeRepository(uow),
|
||||
_cacheHelper);
|
||||
}
|
||||
|
||||
internal virtual IMacroRepository CreateMacroRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return new MacroRepository(uow, _disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current);
|
||||
return new MacroRepository(uow,
|
||||
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current,
|
||||
_logger);
|
||||
}
|
||||
|
||||
public virtual IMemberRepository CreateMemberRepository(IDatabaseUnitOfWork uow)
|
||||
@@ -199,6 +235,7 @@ namespace Umbraco.Core.Persistence
|
||||
return new MemberRepository(
|
||||
uow,
|
||||
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current,
|
||||
_logger,
|
||||
CreateMemberTypeRepository(uow),
|
||||
CreateMemberGroupRepository(uow),
|
||||
CreateTagRepository(uow));
|
||||
@@ -206,12 +243,17 @@ namespace Umbraco.Core.Persistence
|
||||
|
||||
public virtual IMemberTypeRepository CreateMemberTypeRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return new MemberTypeRepository(uow, _disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current);
|
||||
return new MemberTypeRepository(uow,
|
||||
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current,
|
||||
_logger);
|
||||
}
|
||||
|
||||
public virtual IMemberGroupRepository CreateMemberGroupRepository(IDatabaseUnitOfWork uow)
|
||||
{
|
||||
return new MemberGroupRepository(uow, _disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current, _cacheHelper);
|
||||
return new MemberGroupRepository(uow,
|
||||
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current,
|
||||
_logger,
|
||||
_cacheHelper);
|
||||
}
|
||||
|
||||
public virtual IEntityRepository CreateEntityRepository(IDatabaseUnitOfWork uow)
|
||||
|
||||
Reference in New Issue
Block a user