2013-09-13 18:11:20 +10:00
|
|
|
using Umbraco.Core.Configuration;
|
2014-01-28 10:46:59 +11:00
|
|
|
using System;
|
2013-09-13 18:11:20 +10:00
|
|
|
using Umbraco.Core.Configuration.UmbracoSettings;
|
2012-12-09 09:01:00 +05:00
|
|
|
using Umbraco.Core.Persistence.Caching;
|
|
|
|
|
using Umbraco.Core.Persistence.Repositories;
|
|
|
|
|
using Umbraco.Core.Persistence.UnitOfWork;
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Core.Persistence
|
|
|
|
|
{
|
2012-12-10 08:44:17 -01:00
|
|
|
/// <summary>
|
|
|
|
|
/// Used to instantiate each repository type
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class RepositoryFactory
|
|
|
|
|
{
|
2013-09-18 12:54:06 +10:00
|
|
|
private readonly bool _disableAllCache;
|
2014-01-28 10:46:59 +11:00
|
|
|
private readonly CacheHelper _cacheHelper;
|
2013-09-16 17:39:45 +10:00
|
|
|
private readonly IUmbracoSettingsSection _settings;
|
2013-09-13 18:11:20 +10:00
|
|
|
|
2014-02-13 16:56:23 +11:00
|
|
|
#region Ctors
|
2013-09-18 12:54:06 +10:00
|
|
|
public RepositoryFactory()
|
2013-09-25 19:23:41 +10:00
|
|
|
: this(false, UmbracoConfig.For.UmbracoSettings())
|
2013-09-13 18:11:20 +10:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-28 10:46:59 +11:00
|
|
|
public RepositoryFactory(CacheHelper cacheHelper)
|
2014-02-13 16:56:23 +11:00
|
|
|
: this(false, UmbracoConfig.For.UmbracoSettings())
|
2014-01-28 10:46:59 +11:00
|
|
|
{
|
|
|
|
|
if (cacheHelper == null) throw new ArgumentNullException("cacheHelper");
|
|
|
|
|
_disableAllCache = false;
|
|
|
|
|
_cacheHelper = cacheHelper;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public RepositoryFactory(bool disableAllCache, CacheHelper cacheHelper)
|
2014-02-13 16:56:23 +11:00
|
|
|
: this(disableAllCache, UmbracoConfig.For.UmbracoSettings())
|
2014-01-28 10:46:59 +11:00
|
|
|
{
|
|
|
|
|
if (cacheHelper == null) throw new ArgumentNullException("cacheHelper");
|
|
|
|
|
_cacheHelper = cacheHelper;
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-09 13:17:19 +11:00
|
|
|
public RepositoryFactory(bool disableAllCache)
|
2013-09-25 19:23:41 +10:00
|
|
|
: this(disableAllCache, UmbracoConfig.For.UmbracoSettings())
|
2013-09-18 13:26:09 +10:00
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2013-09-18 12:59:46 +10:00
|
|
|
internal RepositoryFactory(bool disableAllCache, IUmbracoSettingsSection settings)
|
2013-09-13 18:11:20 +10:00
|
|
|
{
|
2013-09-18 12:54:06 +10:00
|
|
|
_disableAllCache = disableAllCache;
|
2013-09-18 12:59:46 +10:00
|
|
|
_settings = settings;
|
2014-02-13 16:56:23 +11:00
|
|
|
_cacheHelper = _disableAllCache ? CacheHelper.CreateDisabledCacheHelper() : ApplicationContext.Current.ApplicationCache;
|
2013-09-13 18:11:20 +10:00
|
|
|
}
|
|
|
|
|
|
2014-02-13 16:56:23 +11:00
|
|
|
internal RepositoryFactory(bool disableAllCache, IUmbracoSettingsSection settings, CacheHelper cacheHelper)
|
|
|
|
|
{
|
|
|
|
|
_disableAllCache = disableAllCache;
|
|
|
|
|
_settings = settings;
|
|
|
|
|
_cacheHelper = cacheHelper;
|
|
|
|
|
}
|
|
|
|
|
#endregion
|
|
|
|
|
|
2014-09-01 18:06:24 +10:00
|
|
|
public virtual ITagRepository CreateTagRepository(IDatabaseUnitOfWork uow)
|
2013-10-04 16:11:51 +10:00
|
|
|
{
|
2014-09-01 18:06:24 +10:00
|
|
|
return new TagRepository(
|
2013-10-04 16:11:51 +10:00
|
|
|
uow,
|
|
|
|
|
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current);
|
|
|
|
|
}
|
2013-09-18 12:54:06 +10:00
|
|
|
|
2012-12-12 17:37:13 -01:00
|
|
|
public virtual IContentRepository CreateContentRepository(IDatabaseUnitOfWork uow)
|
2012-12-10 08:44:17 -01:00
|
|
|
{
|
|
|
|
|
return new ContentRepository(
|
2014-02-13 16:46:52 +11:00
|
|
|
uow,
|
2013-09-18 12:54:06 +10:00
|
|
|
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current,
|
2012-12-10 08:44:17 -01:00
|
|
|
CreateContentTypeRepository(uow),
|
2013-10-04 17:13:57 +10:00
|
|
|
CreateTemplateRepository(uow),
|
2014-09-01 18:06:24 +10:00
|
|
|
CreateTagRepository(uow),
|
2014-02-13 16:46:52 +11:00
|
|
|
_cacheHelper) { EnsureUniqueNaming = _settings.Content.EnsureUniqueNaming };
|
2012-12-10 08:44:17 -01:00
|
|
|
}
|
|
|
|
|
|
2012-12-12 17:37:13 -01:00
|
|
|
public virtual IContentTypeRepository CreateContentTypeRepository(IDatabaseUnitOfWork uow)
|
2012-12-10 08:44:17 -01:00
|
|
|
{
|
|
|
|
|
return new ContentTypeRepository(
|
|
|
|
|
uow,
|
2014-01-28 11:30:02 +11:00
|
|
|
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current,
|
2014-04-17 14:23:37 +10:00
|
|
|
CreateTemplateRepository(uow));
|
2012-12-10 08:44:17 -01:00
|
|
|
}
|
|
|
|
|
|
2012-12-12 17:37:13 -01:00
|
|
|
public virtual IDataTypeDefinitionRepository CreateDataTypeDefinitionRepository(IDatabaseUnitOfWork uow)
|
2012-12-10 08:44:17 -01:00
|
|
|
{
|
|
|
|
|
return new DataTypeDefinitionRepository(
|
|
|
|
|
uow,
|
2014-04-17 14:23:37 +10:00
|
|
|
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current,
|
2014-04-17 18:03:34 +10:00
|
|
|
_cacheHelper,
|
|
|
|
|
CreateContentTypeRepository(uow));
|
2012-12-10 08:44:17 -01:00
|
|
|
}
|
|
|
|
|
|
2012-12-12 17:37:13 -01:00
|
|
|
public virtual IDictionaryRepository CreateDictionaryRepository(IDatabaseUnitOfWork uow)
|
2012-12-10 08:44:17 -01:00
|
|
|
{
|
|
|
|
|
return new DictionaryRepository(
|
|
|
|
|
uow,
|
2014-01-28 11:30:02 +11:00
|
|
|
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current,
|
2012-12-10 08:44:17 -01:00
|
|
|
CreateLanguageRepository(uow));
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-12 17:37:13 -01:00
|
|
|
public virtual ILanguageRepository CreateLanguageRepository(IDatabaseUnitOfWork uow)
|
2012-12-10 08:44:17 -01:00
|
|
|
{
|
|
|
|
|
return new LanguageRepository(
|
|
|
|
|
uow,
|
2014-01-28 11:30:02 +11:00
|
|
|
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current);
|
2012-12-10 08:44:17 -01:00
|
|
|
}
|
|
|
|
|
|
2012-12-12 17:37:13 -01:00
|
|
|
public virtual IMediaRepository CreateMediaRepository(IDatabaseUnitOfWork uow)
|
2012-12-10 08:44:17 -01:00
|
|
|
{
|
|
|
|
|
return new MediaRepository(
|
|
|
|
|
uow,
|
2013-09-18 12:54:06 +10:00
|
|
|
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current,
|
2013-10-08 12:25:03 +11:00
|
|
|
CreateMediaTypeRepository(uow),
|
2014-09-01 18:06:24 +10:00
|
|
|
CreateTagRepository(uow)) { EnsureUniqueNaming = _settings.Content.EnsureUniqueNaming };
|
2012-12-10 08:44:17 -01:00
|
|
|
}
|
|
|
|
|
|
2012-12-12 17:37:13 -01:00
|
|
|
public virtual IMediaTypeRepository CreateMediaTypeRepository(IDatabaseUnitOfWork uow)
|
2012-12-10 08:44:17 -01:00
|
|
|
{
|
|
|
|
|
return new MediaTypeRepository(
|
|
|
|
|
uow,
|
2014-01-28 11:30:02 +11:00
|
|
|
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current);
|
2012-12-10 08:44:17 -01:00
|
|
|
}
|
|
|
|
|
|
2012-12-12 17:37:13 -01:00
|
|
|
public virtual IRelationRepository CreateRelationRepository(IDatabaseUnitOfWork uow)
|
2012-12-10 08:44:17 -01:00
|
|
|
{
|
|
|
|
|
return new RelationRepository(
|
|
|
|
|
uow,
|
|
|
|
|
NullCacheProvider.Current,
|
|
|
|
|
CreateRelationTypeRepository(uow));
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-12 17:37:13 -01:00
|
|
|
public virtual IRelationTypeRepository CreateRelationTypeRepository(IDatabaseUnitOfWork uow)
|
2012-12-10 08:44:17 -01:00
|
|
|
{
|
|
|
|
|
return new RelationTypeRepository(
|
|
|
|
|
uow,
|
|
|
|
|
NullCacheProvider.Current);
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-12 17:37:13 -01:00
|
|
|
public virtual IScriptRepository CreateScriptRepository(IUnitOfWork uow)
|
2012-12-10 08:44:17 -01:00
|
|
|
{
|
|
|
|
|
return new ScriptRepository(uow);
|
|
|
|
|
}
|
|
|
|
|
|
2013-10-29 09:24:05 -04:00
|
|
|
public virtual IStylesheetRepository CreateStylesheetRepository(IUnitOfWork uow, IDatabaseUnitOfWork db)
|
2012-12-10 08:44:17 -01:00
|
|
|
{
|
2013-10-29 09:24:05 -04:00
|
|
|
return new StylesheetRepository(uow, db);
|
2012-12-10 08:44:17 -01:00
|
|
|
}
|
|
|
|
|
|
2012-12-12 17:37:13 -01:00
|
|
|
public virtual ITemplateRepository CreateTemplateRepository(IDatabaseUnitOfWork uow)
|
2012-12-10 08:44:17 -01:00
|
|
|
{
|
2013-09-18 12:54:06 +10:00
|
|
|
return new TemplateRepository(uow, _disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current);
|
2012-12-10 08:44:17 -01:00
|
|
|
}
|
2013-08-14 16:12:13 +02:00
|
|
|
|
|
|
|
|
internal virtual ServerRegistrationRepository CreateServerRegistrationRepository(IDatabaseUnitOfWork uow)
|
|
|
|
|
{
|
|
|
|
|
return new ServerRegistrationRepository(
|
|
|
|
|
uow,
|
|
|
|
|
NullCacheProvider.Current);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-20 21:56:58 +11:00
|
|
|
public virtual IUserTypeRepository CreateUserTypeRepository(IDatabaseUnitOfWork uow)
|
2013-08-14 16:12:13 +02:00
|
|
|
{
|
|
|
|
|
return new UserTypeRepository(
|
|
|
|
|
uow,
|
2014-01-06 11:56:53 +11:00
|
|
|
//There's not many user types but we query on users all the time so the result needs to be cached
|
2014-02-20 21:56:58 +11:00
|
|
|
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current);
|
2013-08-14 16:12:13 +02:00
|
|
|
}
|
|
|
|
|
|
2014-02-20 21:56:58 +11:00
|
|
|
public virtual IUserRepository CreateUserRepository(IDatabaseUnitOfWork uow)
|
2014-01-28 10:46:59 +11:00
|
|
|
{
|
2013-08-14 16:12:13 +02:00
|
|
|
return new UserRepository(
|
|
|
|
|
uow,
|
2014-01-28 10:46:59 +11:00
|
|
|
//Need to cache users - we look up user information more than anything in the back office!
|
2014-02-20 21:56:58 +11:00
|
|
|
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current,
|
2014-01-28 10:46:59 +11:00
|
|
|
CreateUserTypeRepository(uow),
|
|
|
|
|
_cacheHelper);
|
2013-08-14 16:12:13 +02:00
|
|
|
}
|
|
|
|
|
|
2013-09-17 20:19:27 +10:00
|
|
|
internal virtual IMacroRepository CreateMacroRepository(IDatabaseUnitOfWork uow)
|
|
|
|
|
{
|
2013-09-20 13:40:32 +10:00
|
|
|
return new MacroRepository(uow, _disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current);
|
2013-09-17 20:19:27 +10:00
|
|
|
}
|
|
|
|
|
|
2014-02-20 21:56:58 +11:00
|
|
|
public virtual IMemberRepository CreateMemberRepository(IDatabaseUnitOfWork uow)
|
2013-08-26 16:59:41 +02:00
|
|
|
{
|
2014-02-11 19:21:36 +11:00
|
|
|
return new MemberRepository(
|
2014-02-13 16:46:52 +11:00
|
|
|
uow,
|
|
|
|
|
_disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current,
|
2014-02-11 19:21:36 +11:00
|
|
|
CreateMemberTypeRepository(uow),
|
2014-02-13 16:46:52 +11:00
|
|
|
CreateMemberGroupRepository(uow),
|
2014-09-01 18:06:24 +10:00
|
|
|
CreateTagRepository(uow));
|
2013-08-26 16:59:41 +02:00
|
|
|
}
|
|
|
|
|
|
2014-02-20 21:56:58 +11:00
|
|
|
public virtual IMemberTypeRepository CreateMemberTypeRepository(IDatabaseUnitOfWork uow)
|
2013-09-02 15:53:09 +02:00
|
|
|
{
|
2014-01-28 11:30:02 +11:00
|
|
|
return new MemberTypeRepository(uow, _disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current);
|
2013-09-02 15:53:09 +02:00
|
|
|
}
|
|
|
|
|
|
2014-02-20 21:56:58 +11:00
|
|
|
public virtual IMemberGroupRepository CreateMemberGroupRepository(IDatabaseUnitOfWork uow)
|
2014-02-10 19:48:16 +11:00
|
|
|
{
|
2014-02-12 17:14:16 +11:00
|
|
|
return new MemberGroupRepository(uow, _disableAllCache ? (IRepositoryCacheProvider)NullCacheProvider.Current : RuntimeCacheProvider.Current, _cacheHelper);
|
2013-08-26 16:59:41 +02:00
|
|
|
}
|
|
|
|
|
|
2014-02-20 21:56:58 +11:00
|
|
|
public virtual IEntityRepository CreateEntityRepository(IDatabaseUnitOfWork uow)
|
2013-08-14 16:12:13 +02:00
|
|
|
{
|
|
|
|
|
return new EntityRepository(uow);
|
|
|
|
|
}
|
|
|
|
|
|
2012-12-10 08:44:17 -01:00
|
|
|
}
|
2012-12-09 09:01:00 +05:00
|
|
|
}
|