using Umbraco.Core.Persistence;
using Umbraco.Core.Persistence.UnitOfWork;
using Umbraco.Core.Publishing;
namespace Umbraco.Core.Services
{
///
/// The Umbraco ServiceContext, which provides access to the following services:
/// , , ,
/// , and .
///
public class ServiceContext
{
private ContentService _contentService;
private UserService _userService;
private MediaService _mediaService;
private MacroService _macroService;
private ContentTypeService _contentTypeService;
private DataTypeService _dataTypeService;
private FileService _fileService;
private LocalizationService _localizationService;
///
/// Constructor
///
///
///
///
internal ServiceContext(IDatabaseUnitOfWorkProvider dbUnitOfWorkProvider, IUnitOfWorkProvider fileUnitOfWorkProvider, IPublishingStrategy publishingStrategy)
{
BuildServiceCache(dbUnitOfWorkProvider, fileUnitOfWorkProvider, publishingStrategy, RepositoryResolver.Current.Factory);
}
///
/// Builds the various services
///
private void BuildServiceCache(
IDatabaseUnitOfWorkProvider dbUnitOfWorkProvider,
IUnitOfWorkProvider fileUnitOfWorkProvider,
IPublishingStrategy publishingStrategy,
RepositoryFactory repositoryFactory)
{
var provider = dbUnitOfWorkProvider;
var fileProvider = fileUnitOfWorkProvider;
if(_userService == null)
_userService = new UserService(provider, repositoryFactory);
if (_contentService == null)
_contentService = new ContentService(provider, repositoryFactory, publishingStrategy, _userService);
if(_mediaService == null)
_mediaService = new MediaService(provider, repositoryFactory);
if(_macroService == null)
_macroService = new MacroService(fileProvider, repositoryFactory);
if(_contentTypeService == null)
_contentTypeService = new ContentTypeService(provider, repositoryFactory, _contentService, _mediaService);
if(_dataTypeService == null)
_dataTypeService = new DataTypeService(provider, repositoryFactory);
if(_fileService == null)
_fileService = new FileService(fileProvider, provider, repositoryFactory);
if(_localizationService == null)
_localizationService = new LocalizationService(provider, repositoryFactory);
}
///
/// Gets the
///
public IContentService ContentService
{
get { return _contentService; }
}
///
/// Gets the
///
public IContentTypeService ContentTypeService
{
get { return _contentTypeService; }
}
///
/// Gets the
///
public IDataTypeService DataTypeService
{
get { return _dataTypeService; }
}
///
/// Gets the
///
public IFileService FileService
{
get { return _fileService; }
}
///
/// Gets the
///
public ILocalizationService LocalizationService
{
get { return _localizationService; }
}
///
/// Gets the
///
public IMediaService MediaService
{
get { return _mediaService; }
}
///
/// Gets the
///
internal IMacroService MacroService
{
get { return _macroService; }
}
///
/// Gets the
///
internal IUserService UserService
{
get { return _userService; }
}
}
}