Exemplo n.º 1
0
        /// <summary>
        /// Creates a service context with a RepositoryFactory which is used to construct Services
        /// </summary>
        /// <param name="repositoryFactory"></param>
        /// <param name="dbUnitOfWorkProvider"></param>
        /// <param name="fileUnitOfWorkProvider"></param>
        /// <param name="publishingStrategy"></param>
        /// <param name="cache"></param>
        /// <param name="logger"></param>
        /// <param name="eventMessagesFactory"></param>
        public ServiceContext(
            RepositoryFactory repositoryFactory,
            IDatabaseUnitOfWorkProvider dbUnitOfWorkProvider,
            IUnitOfWorkProvider fileUnitOfWorkProvider,
            BasePublishingStrategy publishingStrategy,
            CacheHelper cache,
            ILogger logger,
            IEventMessagesFactory eventMessagesFactory)
        {
            if (repositoryFactory == null)
            {
                throw new ArgumentNullException("repositoryFactory");
            }
            if (dbUnitOfWorkProvider == null)
            {
                throw new ArgumentNullException("dbUnitOfWorkProvider");
            }
            if (fileUnitOfWorkProvider == null)
            {
                throw new ArgumentNullException("fileUnitOfWorkProvider");
            }
            if (publishingStrategy == null)
            {
                throw new ArgumentNullException("publishingStrategy");
            }
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }
            if (eventMessagesFactory == null)
            {
                throw new ArgumentNullException("eventMessagesFactory");
            }

            BuildServiceCache(dbUnitOfWorkProvider, fileUnitOfWorkProvider, publishingStrategy, cache,
                              repositoryFactory,
                              logger, eventMessagesFactory);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Builds the various services
        /// </summary>
        private void BuildServiceCache(
            IDatabaseUnitOfWorkProvider dbUnitOfWorkProvider,
            IUnitOfWorkProvider fileUnitOfWorkProvider,
            BasePublishingStrategy publishingStrategy,
            Lazy <RepositoryFactory> repositoryFactory)
        {
            var provider     = dbUnitOfWorkProvider;
            var fileProvider = fileUnitOfWorkProvider;

            if (_serverRegistrationService == null)
            {
                _serverRegistrationService = new Lazy <ServerRegistrationService>(() => new ServerRegistrationService(provider, repositoryFactory.Value));
            }

            if (_userService == null)
            {
                _userService = new Lazy <IUserService>(() => new UserService(provider, repositoryFactory.Value));
            }

            if (_memberService == null)
            {
                _memberService = new Lazy <IMemberService>(() => new MemberService(provider, repositoryFactory.Value));
            }

            if (_contentService == null)
            {
                _contentService = new Lazy <IContentService>(() => new ContentService(provider, repositoryFactory.Value, publishingStrategy));
            }

            if (_mediaService == null)
            {
                _mediaService = new Lazy <IMediaService>(() => new MediaService(provider, repositoryFactory.Value));
            }

            if (_contentTypeService == null)
            {
                _contentTypeService = new Lazy <IContentTypeService>(() => new ContentTypeService(provider, repositoryFactory.Value, _contentService.Value, _mediaService.Value));
            }

            if (_dataTypeService == null)
            {
                _dataTypeService = new Lazy <IDataTypeService>(() => new DataTypeService(provider, repositoryFactory.Value));
            }

            if (_fileService == null)
            {
                _fileService = new Lazy <IFileService>(() => new FileService(fileProvider, provider, repositoryFactory.Value));
            }

            if (_localizationService == null)
            {
                _localizationService = new Lazy <ILocalizationService>(() => new LocalizationService(provider, repositoryFactory.Value));
            }

            if (_packagingService == null)
            {
                _packagingService = new Lazy <PackagingService>(() => new PackagingService(_contentService.Value, _contentTypeService.Value, _mediaService.Value, _dataTypeService.Value, _fileService.Value, _localizationService.Value, repositoryFactory.Value, provider));
            }

            if (_entityService == null)
            {
                _entityService = new Lazy <IEntityService>(() => new EntityService(provider, repositoryFactory.Value, _contentService.Value, _contentTypeService.Value, _mediaService.Value, _dataTypeService.Value));
            }

            if (_relationService == null)
            {
                _relationService = new Lazy <RelationService>(() => new RelationService(provider, repositoryFactory.Value, _entityService.Value));
            }

            if (_memberTypeService == null)
            {
                _memberTypeService = new Lazy <IMemberTypeService>(() => new MemberTypeService(provider, repositoryFactory.Value));
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// Constructor used to instantiate the core services
 /// </summary>
 /// <param name="dbUnitOfWorkProvider"></param>
 /// <param name="fileUnitOfWorkProvider"></param>
 /// <param name="publishingStrategy"></param>
 internal ServiceContext(IDatabaseUnitOfWorkProvider dbUnitOfWorkProvider, IUnitOfWorkProvider fileUnitOfWorkProvider, BasePublishingStrategy publishingStrategy)
 {
     BuildServiceCache(dbUnitOfWorkProvider, fileUnitOfWorkProvider, publishingStrategy,
                       //this needs to be lazy because when we create the service context it's generally before the
                       //resolvers have been initialized!
                       new Lazy <RepositoryFactory>(() => RepositoryResolver.Current.Factory));
 }
Exemplo n.º 4
0
        /// <summary>
        /// Builds the various services
        /// </summary>
        private void BuildServiceCache(
            IDatabaseUnitOfWorkProvider dbUnitOfWorkProvider,
            IUnitOfWorkProvider fileUnitOfWorkProvider,
            BasePublishingStrategy publishingStrategy,
            CacheHelper cache,
            RepositoryFactory repositoryFactory,
            ILogger logger,
            IEventMessagesFactory eventMessagesFactory)
        {
            var provider     = dbUnitOfWorkProvider;
            var fileProvider = fileUnitOfWorkProvider;

            if (_migrationEntryService == null)
            {
                _migrationEntryService = new Lazy <IMigrationEntryService>(() => new MigrationEntryService(provider, repositoryFactory, logger, eventMessagesFactory));
            }

            if (_externalLoginService == null)
            {
                _externalLoginService = new Lazy <IExternalLoginService>(() => new ExternalLoginService(provider, repositoryFactory, logger, eventMessagesFactory));
            }

            if (_publicAccessService == null)
            {
                _publicAccessService = new Lazy <IPublicAccessService>(() => new PublicAccessService(provider, repositoryFactory, logger, eventMessagesFactory));
            }

            if (_taskService == null)
            {
                _taskService = new Lazy <ITaskService>(() => new TaskService(provider, repositoryFactory, logger, eventMessagesFactory));
            }

            if (_domainService == null)
            {
                _domainService = new Lazy <IDomainService>(() => new DomainService(provider, repositoryFactory, logger, eventMessagesFactory));
            }

            if (_auditService == null)
            {
                _auditService = new Lazy <IAuditService>(() => new AuditService(provider, repositoryFactory, logger, eventMessagesFactory));
            }

            if (_localizedTextService == null)
            {
                _localizedTextService = new Lazy <ILocalizedTextService>(() => new LocalizedTextService(
                                                                             new Lazy <LocalizedTextServiceFileSources>(() =>
                {
                    var mainLangFolder   = new DirectoryInfo(IOHelper.MapPath(SystemDirectories.Umbraco + "/config/lang/"));
                    var appPlugins       = new DirectoryInfo(IOHelper.MapPath(SystemDirectories.AppPlugins));
                    var configLangFolder = new DirectoryInfo(IOHelper.MapPath(SystemDirectories.Config + "/lang/"));

                    var pluginLangFolders = appPlugins.Exists == false
                            ? Enumerable.Empty <LocalizedTextServiceSupplementaryFileSource>()
                            : appPlugins.GetDirectories()
                                            .SelectMany(x => x.GetDirectories("Lang"))
                                            .SelectMany(x => x.GetFiles("*.xml", SearchOption.TopDirectoryOnly))
                                            .Where(x => Path.GetFileNameWithoutExtension(x.FullName).Length == 5)
                                            .Select(x => new LocalizedTextServiceSupplementaryFileSource(x, false));

                    //user defined langs that overwrite the default, these should not be used by plugin creators
                    var userLangFolders = configLangFolder.Exists == false
                            ? Enumerable.Empty <LocalizedTextServiceSupplementaryFileSource>()
                            : configLangFolder
                                          .GetFiles("*.user.xml", SearchOption.TopDirectoryOnly)
                                          .Where(x => Path.GetFileNameWithoutExtension(x.FullName).Length == 10)
                                          .Select(x => new LocalizedTextServiceSupplementaryFileSource(x, true));

                    return(new LocalizedTextServiceFileSources(
                               logger,
                               cache.RuntimeCache,
                               mainLangFolder,
                               pluginLangFolders.Concat(userLangFolders)));
                }),
                                                                             logger));
            }


            if (_notificationService == null)
            {
                _notificationService = new Lazy <INotificationService>(() => new NotificationService(provider, _userService.Value, _contentService.Value, logger));
            }

            if (_serverRegistrationService == null)
            {
                _serverRegistrationService = new Lazy <IServerRegistrationService>(() => new ServerRegistrationService(provider, repositoryFactory, logger, eventMessagesFactory));
            }

            if (_userService == null)
            {
                _userService = new Lazy <IUserService>(() => new UserService(provider, repositoryFactory, logger, eventMessagesFactory));
            }

            if (_memberService == null)
            {
                _memberService = new Lazy <IMemberService>(() => new MemberService(provider, repositoryFactory, logger, eventMessagesFactory, _memberGroupService.Value, _dataTypeService.Value));
            }

            if (_contentService == null)
            {
                _contentService = new Lazy <IContentService>(() => new ContentService(provider, repositoryFactory, logger, eventMessagesFactory, publishingStrategy, _dataTypeService.Value, _userService.Value));
            }

            if (_mediaService == null)
            {
                _mediaService = new Lazy <IMediaService>(() => new MediaService(provider, repositoryFactory, logger, eventMessagesFactory, _dataTypeService.Value, _userService.Value));
            }

            if (_contentTypeService == null)
            {
                _contentTypeService = new Lazy <IContentTypeService>(() => new ContentTypeService(provider, repositoryFactory, logger, eventMessagesFactory, _contentService.Value, _mediaService.Value));
            }

            if (_dataTypeService == null)
            {
                _dataTypeService = new Lazy <IDataTypeService>(() => new DataTypeService(provider, repositoryFactory, logger, eventMessagesFactory));
            }

            if (_fileService == null)
            {
                _fileService = new Lazy <IFileService>(() => new FileService(fileProvider, provider, repositoryFactory));
            }

            if (_localizationService == null)
            {
                _localizationService = new Lazy <ILocalizationService>(() => new LocalizationService(provider, repositoryFactory, logger, eventMessagesFactory));
            }

            if (_packagingService == null)
            {
                _packagingService = new Lazy <IPackagingService>(() => new PackagingService(logger, _contentService.Value, _contentTypeService.Value, _mediaService.Value, _macroService.Value, _dataTypeService.Value, _fileService.Value, _localizationService.Value, _userService.Value, repositoryFactory, provider));
            }

            if (_entityService == null)
            {
                _entityService = new Lazy <IEntityService>(() => new EntityService(
                                                               provider, repositoryFactory, logger, eventMessagesFactory,
                                                               _contentService.Value, _contentTypeService.Value, _mediaService.Value, _dataTypeService.Value, _memberService.Value, _memberTypeService.Value,
                                                               cache.RuntimeCache));
            }

            if (_relationService == null)
            {
                _relationService = new Lazy <IRelationService>(() => new RelationService(provider, repositoryFactory, logger, eventMessagesFactory, _entityService.Value));
            }

            if (_treeService == null)
            {
                _treeService = new Lazy <IApplicationTreeService>(() => new ApplicationTreeService(logger, cache));
            }

            if (_sectionService == null)
            {
                _sectionService = new Lazy <ISectionService>(() => new SectionService(_userService.Value, _treeService.Value, provider, cache));
            }

            if (_macroService == null)
            {
                _macroService = new Lazy <IMacroService>(() => new MacroService(provider, repositoryFactory, logger, eventMessagesFactory));
            }

            if (_memberTypeService == null)
            {
                _memberTypeService = new Lazy <IMemberTypeService>(() => new MemberTypeService(provider, repositoryFactory, logger, eventMessagesFactory, _memberService.Value));
            }

            if (_tagService == null)
            {
                _tagService = new Lazy <ITagService>(() => new TagService(provider, repositoryFactory, logger, eventMessagesFactory));
            }

            if (_memberGroupService == null)
            {
                _memberGroupService = new Lazy <IMemberGroupService>(() => new MemberGroupService(provider, repositoryFactory, logger, eventMessagesFactory));
            }
        }