public EntityService(IDatabaseUnitOfWorkProvider provider, RepositoryFactory repositoryFactory, ILogger logger, IEventMessagesFactory eventMessagesFactory,
                             IContentService contentService, IContentTypeService contentTypeService, IMediaService mediaService, IDataTypeService dataTypeService,
                             IMemberService memberService, IMemberTypeService memberTypeService, IdkMap idkMap)
            : base(provider, repositoryFactory, logger, eventMessagesFactory)
        {
            _idkMap = idkMap;

            _supportedObjectTypes = new Dictionary <string, Tuple <UmbracoObjectTypes, Func <int, IUmbracoEntity> > >
            {
                { typeof(IDataTypeDefinition).FullName, new Tuple <UmbracoObjectTypes, Func <int, IUmbracoEntity> >(UmbracoObjectTypes.DataType, dataTypeService.GetDataTypeDefinitionById) },
                { typeof(IContent).FullName, new Tuple <UmbracoObjectTypes, Func <int, IUmbracoEntity> >(UmbracoObjectTypes.Document, contentService.GetById) },
                { typeof(IContentType).FullName, new Tuple <UmbracoObjectTypes, Func <int, IUmbracoEntity> >(UmbracoObjectTypes.DocumentType, contentTypeService.GetContentType) },
                { typeof(IMedia).FullName, new Tuple <UmbracoObjectTypes, Func <int, IUmbracoEntity> >(UmbracoObjectTypes.Media, mediaService.GetById) },
                { typeof(IMediaType).FullName, new Tuple <UmbracoObjectTypes, Func <int, IUmbracoEntity> >(UmbracoObjectTypes.MediaType, contentTypeService.GetMediaType) },
                { typeof(IMember).FullName, new Tuple <UmbracoObjectTypes, Func <int, IUmbracoEntity> >(UmbracoObjectTypes.Member, memberService.GetById) },
                { typeof(IMemberType).FullName, new Tuple <UmbracoObjectTypes, Func <int, IUmbracoEntity> >(UmbracoObjectTypes.MemberType, memberTypeService.Get) },
            };
        }
Exemple #2
0
        /// <summary>
        /// Creates a service context with a RepositoryFactory which is used to construct Services
        /// </summary>
        /// <param name="repositoryFactory"></param>
        /// <param name="provider"></param>
        /// <param name="cache"></param>
        /// <param name="logger"></param>
        /// <param name="eventMessagesFactory"></param>
        public ServiceContext(
            RepositoryFactory repositoryFactory,
            IScopeUnitOfWorkProvider provider,
            CacheHelper cache,
            ILogger logger,
            IEventMessagesFactory eventMessagesFactory)
        {
            if (repositoryFactory == null)
            {
                throw new ArgumentNullException("repositoryFactory");
            }
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }
            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }
            if (eventMessagesFactory == null)
            {
                throw new ArgumentNullException("eventMessagesFactory");
            }

            EventMessagesFactory = eventMessagesFactory;

            IdkMap = new IdkMap(provider);

            BuildServiceCache(provider, cache,
                              repositoryFactory,
                              logger, eventMessagesFactory, IdkMap);
        }
Exemple #3
0
        /// <summary>
        /// Builds the various services
        /// </summary>
        private void BuildServiceCache(
            IScopeUnitOfWorkProvider provider,
            CacheHelper cache,
            RepositoryFactory repositoryFactory,
            ILogger logger,
            IEventMessagesFactory eventMessagesFactory,
            IdkMap idkMap)
        {
            EventMessagesFactory = eventMessagesFactory;

            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, _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(provider, repositoryFactory, logger, eventMessagesFactory));
            }

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

            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,
                                                               idkMap));
            }

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

            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));
            }

            if (_redirectUrlService == null)
            {
                _redirectUrlService = new Lazy <IRedirectUrlService>(() => new RedirectUrlService(provider, repositoryFactory, logger, eventMessagesFactory));
            }
        }