Making minor correct to ServiceContext as per Shannons recommendation.
Adding resolver reset to publishing test tear down.
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Umbraco.Core.Persistence.UnitOfWork;
|
|
||||||
|
|
||||||
namespace Umbraco.Core.Persistence.Repositories
|
namespace Umbraco.Core.Persistence.Repositories
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,120 +4,115 @@ using Umbraco.Core.Persistence.UnitOfWork;
|
|||||||
|
|
||||||
namespace Umbraco.Core.Persistence
|
namespace Umbraco.Core.Persistence
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Used to instantiate each repository type
|
/// Used to instantiate each repository type
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class RepositoryFactory
|
public class RepositoryFactory
|
||||||
{
|
{
|
||||||
|
internal virtual IUserTypeRepository CreateUserTypeRepository(IUnitOfWork uow)
|
||||||
|
{
|
||||||
|
return new UserTypeRepository(
|
||||||
|
uow,
|
||||||
|
NullCacheProvider.Current);
|
||||||
|
}
|
||||||
|
|
||||||
internal virtual IUserTypeRepository CreateUserTypeRepository(IUnitOfWork uow)
|
internal virtual IUserRepository CreateUserRepository(IUnitOfWork uow)
|
||||||
{
|
{
|
||||||
return new UserTypeRepository(
|
return new UserRepository(
|
||||||
uow,
|
uow,
|
||||||
NullCacheProvider.Current);
|
NullCacheProvider.Current,
|
||||||
|
CreateUserTypeRepository(uow));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
public virtual IContentRepository CreateContentRepository(IUnitOfWork uow)
|
||||||
|
{
|
||||||
|
return new ContentRepository(
|
||||||
|
uow,
|
||||||
|
RuntimeCacheProvider.Current,
|
||||||
|
CreateContentTypeRepository(uow),
|
||||||
|
CreateTemplateRepository(uow));
|
||||||
|
}
|
||||||
|
|
||||||
internal virtual IUserRepository CreateUserRepository(IUnitOfWork uow)
|
public virtual IContentTypeRepository CreateContentTypeRepository(IUnitOfWork uow)
|
||||||
{
|
{
|
||||||
return new UserRepository(
|
return new ContentTypeRepository(
|
||||||
uow,
|
uow,
|
||||||
NullCacheProvider.Current,
|
InMemoryCacheProvider.Current,
|
||||||
CreateUserTypeRepository(uow));
|
new TemplateRepository(uow, NullCacheProvider.Current));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
public virtual IDataTypeDefinitionRepository CreateDataTypeDefinitionRepository(IUnitOfWork uow)
|
||||||
|
{
|
||||||
|
return new DataTypeDefinitionRepository(
|
||||||
|
uow,
|
||||||
|
NullCacheProvider.Current);
|
||||||
|
}
|
||||||
|
|
||||||
public virtual IContentRepository CreateContentRepository(IUnitOfWork uow)
|
public virtual IDictionaryRepository CreateDictionaryRepository(IUnitOfWork uow)
|
||||||
{
|
{
|
||||||
return new ContentRepository(
|
return new DictionaryRepository(
|
||||||
uow,
|
uow,
|
||||||
RuntimeCacheProvider.Current,
|
InMemoryCacheProvider.Current,
|
||||||
CreateContentTypeRepository(uow),
|
CreateLanguageRepository(uow));
|
||||||
CreateTemplateRepository(uow));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public virtual IContentTypeRepository CreateContentTypeRepository(IUnitOfWork uow)
|
public virtual ILanguageRepository CreateLanguageRepository(IUnitOfWork uow)
|
||||||
{
|
{
|
||||||
return new ContentTypeRepository(
|
return new LanguageRepository(
|
||||||
uow,
|
uow,
|
||||||
InMemoryCacheProvider.Current,
|
InMemoryCacheProvider.Current);
|
||||||
new TemplateRepository(uow, NullCacheProvider.Current));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public virtual IDataTypeDefinitionRepository CreateDataTypeDefinitionRepository(IUnitOfWork uow)
|
internal virtual IMacroRepository CreateMacroRepository(IUnitOfWork uow)
|
||||||
{
|
{
|
||||||
return new DataTypeDefinitionRepository(
|
return new MacroRepository(
|
||||||
uow,
|
uow,
|
||||||
NullCacheProvider.Current);
|
InMemoryCacheProvider.Current);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual IDictionaryRepository CreateDictionaryRepository(IUnitOfWork uow)
|
public virtual IMediaRepository CreateMediaRepository(IUnitOfWork uow)
|
||||||
{
|
{
|
||||||
return new DictionaryRepository(
|
return new MediaRepository(
|
||||||
uow,
|
uow,
|
||||||
InMemoryCacheProvider.Current,
|
RuntimeCacheProvider.Current,
|
||||||
CreateLanguageRepository(uow));
|
CreateMediaTypeRepository(uow));
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual ILanguageRepository CreateLanguageRepository(IUnitOfWork uow)
|
public virtual IMediaTypeRepository CreateMediaTypeRepository(IUnitOfWork uow)
|
||||||
{
|
{
|
||||||
return new LanguageRepository(
|
return new MediaTypeRepository(
|
||||||
uow,
|
uow,
|
||||||
InMemoryCacheProvider.Current);
|
InMemoryCacheProvider.Current);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal virtual IMacroRepository CreateMacroRepository(IUnitOfWork uow)
|
public virtual IRelationRepository CreateRelationRepository(IUnitOfWork uow)
|
||||||
{
|
{
|
||||||
return new MacroRepository(
|
return new RelationRepository(
|
||||||
uow,
|
uow,
|
||||||
InMemoryCacheProvider.Current);
|
NullCacheProvider.Current,
|
||||||
}
|
CreateRelationTypeRepository(uow));
|
||||||
|
}
|
||||||
|
|
||||||
public virtual IMediaRepository CreateMediaRepository(IUnitOfWork uow)
|
public virtual IRelationTypeRepository CreateRelationTypeRepository(IUnitOfWork uow)
|
||||||
{
|
{
|
||||||
return new MediaRepository(
|
return new RelationTypeRepository(
|
||||||
uow,
|
uow,
|
||||||
RuntimeCacheProvider.Current,
|
NullCacheProvider.Current);
|
||||||
CreateMediaTypeRepository(uow));
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public virtual IMediaTypeRepository CreateMediaTypeRepository(IUnitOfWork uow)
|
public virtual IScriptRepository CreateScriptRepository(IUnitOfWork uow)
|
||||||
{
|
{
|
||||||
return new MediaTypeRepository(
|
return new ScriptRepository(uow);
|
||||||
uow,
|
}
|
||||||
InMemoryCacheProvider.Current);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual IRelationRepository CreateRelationRepository(IUnitOfWork uow)
|
public virtual IStylesheetRepository CreateStylesheetRepository(IUnitOfWork uow)
|
||||||
{
|
{
|
||||||
return new RelationRepository(
|
return new StylesheetRepository(uow);
|
||||||
uow,
|
}
|
||||||
NullCacheProvider.Current,
|
|
||||||
CreateRelationTypeRepository(uow));
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual IRelationTypeRepository CreateRelationTypeRepository(IUnitOfWork uow)
|
public virtual ITemplateRepository CreateTemplateRepository(IUnitOfWork uow)
|
||||||
{
|
{
|
||||||
return new RelationTypeRepository(
|
return new TemplateRepository(uow, NullCacheProvider.Current);
|
||||||
uow,
|
}
|
||||||
NullCacheProvider.Current);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public virtual IScriptRepository CreateScriptRepository(IUnitOfWork uow)
|
|
||||||
{
|
|
||||||
return new ScriptRepository(uow);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual IStylesheetRepository CreateStylesheetRepository(IUnitOfWork uow)
|
|
||||||
{
|
|
||||||
return new StylesheetRepository(uow);
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual ITemplateRepository CreateTemplateRepository(IUnitOfWork uow)
|
|
||||||
{
|
|
||||||
return new TemplateRepository(uow, NullCacheProvider.Current);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -12,7 +12,14 @@ namespace Umbraco.Core.Services
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ServiceContext
|
public class ServiceContext
|
||||||
{
|
{
|
||||||
private readonly ConcurrentDictionary<string, IService> _cache = new ConcurrentDictionary<string, IService>();
|
private ContentService _contentService;
|
||||||
|
private UserService _userService;
|
||||||
|
private MediaService _mediaService;
|
||||||
|
private MacroService _macroService;
|
||||||
|
private ContentTypeService _contentTypeService;
|
||||||
|
private DataTypeService _dataTypeService;
|
||||||
|
private FileService _fileService;
|
||||||
|
private LocalizationService _localizationService;
|
||||||
|
|
||||||
#region Singleton
|
#region Singleton
|
||||||
private static readonly Lazy<ServiceContext> lazy = new Lazy<ServiceContext>(() => new ServiceContext());
|
private static readonly Lazy<ServiceContext> lazy = new Lazy<ServiceContext>(() => new ServiceContext());
|
||||||
@@ -29,39 +36,37 @@ namespace Umbraco.Core.Services
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Builds the various services and adds them to the internal cache
|
/// Builds the various services
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void BuildServiceCache()
|
private void BuildServiceCache()
|
||||||
{
|
{
|
||||||
if (_cache.IsEmpty == false) return;//Only proceed to build cache if cache is empty
|
|
||||||
|
|
||||||
var provider = new PetaPocoUnitOfWorkProvider();
|
var provider = new PetaPocoUnitOfWorkProvider();
|
||||||
var fileProvider = new FileUnitOfWorkProvider();
|
var fileProvider = new FileUnitOfWorkProvider();
|
||||||
var publishingStrategy = new PublishingStrategy();
|
var publishingStrategy = new PublishingStrategy();
|
||||||
|
|
||||||
var userService = new UserService(provider);
|
if(_userService == null)
|
||||||
_cache.AddOrUpdate(typeof(UserService).Name, userService, (x, y) => userService);
|
_userService = new UserService(provider);
|
||||||
|
|
||||||
var contentService = new ContentService(provider, publishingStrategy, userService);
|
if (_contentService == null)
|
||||||
_cache.AddOrUpdate(typeof (IContentService).Name, contentService, (x, y) => contentService);
|
_contentService = new ContentService(provider, publishingStrategy, _userService);
|
||||||
|
|
||||||
var mediaService = new MediaService(provider);
|
if(_mediaService == null)
|
||||||
_cache.AddOrUpdate(typeof(IMediaService).Name, mediaService, (x, y) => mediaService);
|
_mediaService = new MediaService(provider);
|
||||||
|
|
||||||
var macroService = new MacroService(fileProvider);
|
if(_macroService == null)
|
||||||
_cache.AddOrUpdate(typeof (IMacroService).Name, macroService, (x, y) => macroService);
|
_macroService = new MacroService(fileProvider);
|
||||||
|
|
||||||
var contentTypeService = new ContentTypeService(contentService, mediaService, provider);
|
if(_contentTypeService == null)
|
||||||
_cache.AddOrUpdate(typeof(IContentTypeService).Name, contentTypeService, (x, y) => contentTypeService);
|
_contentTypeService = new ContentTypeService(_contentService, _mediaService, provider);
|
||||||
|
|
||||||
var dataTypeService = new DataTypeService(provider);
|
if(_dataTypeService == null)
|
||||||
_cache.AddOrUpdate(typeof(IDataTypeService).Name, dataTypeService, (x, y) => dataTypeService);
|
_dataTypeService = new DataTypeService(provider);
|
||||||
|
|
||||||
var fileService = new FileService(fileProvider, provider);
|
if(_fileService == null)
|
||||||
_cache.AddOrUpdate(typeof(IFileService).Name, fileService, (x, y) => fileService);
|
_fileService = new FileService(fileProvider, provider);
|
||||||
|
|
||||||
var localizationService = new LocalizationService(provider);
|
if(_localizationService == null)
|
||||||
_cache.AddOrUpdate(typeof(ILocalizationService).Name, localizationService, (x, y) => localizationService);
|
_localizationService = new LocalizationService(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -69,7 +74,7 @@ namespace Umbraco.Core.Services
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public IContentService ContentService
|
public IContentService ContentService
|
||||||
{
|
{
|
||||||
get { return _cache[typeof (IContentService).Name] as IContentService; }
|
get { return _contentService; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -77,7 +82,7 @@ namespace Umbraco.Core.Services
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public IContentTypeService ContentTypeService
|
public IContentTypeService ContentTypeService
|
||||||
{
|
{
|
||||||
get { return _cache[typeof(IContentTypeService).Name] as IContentTypeService; }
|
get { return _contentTypeService; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -85,7 +90,7 @@ namespace Umbraco.Core.Services
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public IDataTypeService DataTypeService
|
public IDataTypeService DataTypeService
|
||||||
{
|
{
|
||||||
get { return _cache[typeof(IDataTypeService).Name] as IDataTypeService; }
|
get { return _dataTypeService; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -93,7 +98,7 @@ namespace Umbraco.Core.Services
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public IFileService FileService
|
public IFileService FileService
|
||||||
{
|
{
|
||||||
get { return _cache[typeof (IFileService).Name] as IFileService; }
|
get { return _fileService; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -101,7 +106,7 @@ namespace Umbraco.Core.Services
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public ILocalizationService LocalizationService
|
public ILocalizationService LocalizationService
|
||||||
{
|
{
|
||||||
get { return _cache[typeof(ILocalizationService).Name] as ILocalizationService; }
|
get { return _localizationService; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -109,7 +114,7 @@ namespace Umbraco.Core.Services
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public IMediaService MediaService
|
public IMediaService MediaService
|
||||||
{
|
{
|
||||||
get { return _cache[typeof(IMediaService).Name] as IMediaService; }
|
get { return _mediaService; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -117,7 +122,7 @@ namespace Umbraco.Core.Services
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal IMacroService MacroService
|
internal IMacroService MacroService
|
||||||
{
|
{
|
||||||
get { return _cache[typeof(IMacroService).Name] as IMacroService; }
|
get { return _macroService; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -125,7 +130,7 @@ namespace Umbraco.Core.Services
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal IUserService UserService
|
internal IUserService UserService
|
||||||
{
|
{
|
||||||
get { return _cache[typeof(IUserService).Name] as IUserService; }
|
get { return _userService; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,6 +8,7 @@ using Umbraco.Core.Configuration;
|
|||||||
using Umbraco.Core.IO;
|
using Umbraco.Core.IO;
|
||||||
using Umbraco.Core.Models;
|
using Umbraco.Core.Models;
|
||||||
using Umbraco.Core.ObjectResolution;
|
using Umbraco.Core.ObjectResolution;
|
||||||
|
using Umbraco.Core.Persistence;
|
||||||
using Umbraco.Tests.TestHelpers;
|
using Umbraco.Tests.TestHelpers;
|
||||||
using Umbraco.Tests.TestHelpers.Entities;
|
using Umbraco.Tests.TestHelpers.Entities;
|
||||||
using Umbraco.Web.Strategies;
|
using Umbraco.Web.Strategies;
|
||||||
@@ -54,6 +55,8 @@ namespace Umbraco.Tests.Publishing
|
|||||||
ApplicationContext.Current = null;
|
ApplicationContext.Current = null;
|
||||||
Resolution.IsFrozen = false;
|
Resolution.IsFrozen = false;
|
||||||
|
|
||||||
|
RepositoryResolver.Reset();
|
||||||
|
|
||||||
string path = TestHelper.CurrentAssemblyDirectory;
|
string path = TestHelper.CurrentAssemblyDirectory;
|
||||||
AppDomain.CurrentDomain.SetData("DataDirectory", null);
|
AppDomain.CurrentDomain.SetData("DataDirectory", null);
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ using System.Linq;
|
|||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using Umbraco.Core.Models;
|
using Umbraco.Core.Models;
|
||||||
using Umbraco.Core.Persistence;
|
using Umbraco.Core.Persistence;
|
||||||
using Umbraco.Core.Persistence.Caching;
|
|
||||||
using Umbraco.Core.Persistence.Repositories;
|
using Umbraco.Core.Persistence.Repositories;
|
||||||
using Umbraco.Core.Persistence.UnitOfWork;
|
using Umbraco.Core.Persistence.UnitOfWork;
|
||||||
using Umbraco.Tests.TestHelpers;
|
using Umbraco.Tests.TestHelpers;
|
||||||
@@ -12,7 +11,7 @@ using Umbraco.Tests.TestHelpers.Entities;
|
|||||||
|
|
||||||
namespace Umbraco.Tests.Services
|
namespace Umbraco.Tests.Services
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture, NUnit.Framework.Ignore]
|
||||||
public class ContentServicePerformanceTest : BaseDatabaseFactoryTest
|
public class ContentServicePerformanceTest : BaseDatabaseFactoryTest
|
||||||
{
|
{
|
||||||
[SetUp]
|
[SetUp]
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ namespace Umbraco.Tests.TestHelpers
|
|||||||
ServiceContext = null;
|
ServiceContext = null;
|
||||||
Resolution.IsFrozen = false;
|
Resolution.IsFrozen = false;
|
||||||
|
|
||||||
RepositoryResolver.Reset();
|
RepositoryResolver.Reset();
|
||||||
|
|
||||||
string path = TestHelper.CurrentAssemblyDirectory;
|
string path = TestHelper.CurrentAssemblyDirectory;
|
||||||
AppDomain.CurrentDomain.SetData("DataDirectory", null);
|
AppDomain.CurrentDomain.SetData("DataDirectory", null);
|
||||||
|
|||||||
Reference in New Issue
Block a user