/// <summary> /// Adds all core Umbraco services required to run which may be replaced later in the pipeline /// </summary> public static IUmbracoBuilder AddCoreInitialServices(this IUmbracoBuilder builder) { builder .AddMainDom() .AddLogging(); builder.Services.AddSingleton <IUmbracoDatabaseFactory, UmbracoDatabaseFactory>(); builder.Services.AddSingleton(factory => factory.GetRequiredService <IUmbracoDatabaseFactory>().CreateDatabase()); builder.Services.AddSingleton(factory => factory.GetRequiredService <IUmbracoDatabaseFactory>().SqlContext); builder.NPocoMappers().Add <NullableDateMapper>(); builder.PackageMigrationPlans().Add(() => builder.TypeLoader.GetPackageMigrationPlans()); builder.Services.AddSingleton <IRuntimeState, RuntimeState>(); builder.Services.AddSingleton <IRuntime, CoreRuntime>(); builder.Services.AddSingleton <PendingPackageMigrations>(); builder.AddNotificationAsyncHandler <RuntimeUnattendedInstallNotification, UnattendedInstaller>(); builder.AddNotificationAsyncHandler <RuntimeUnattendedUpgradeNotification, UnattendedUpgrader>(); // composers builder .AddRepositories() .AddServices() .AddCoreMappingProfiles() .AddFileSystems() .AddWebAssets(); // register persistence mappers - required by database factory so needs to be done here // means the only place the collection can be modified is in a runtime - afterwards it // has been frozen and it is too late builder.Mappers().AddCoreMappers(); // register the scope provider builder.Services.AddSingleton <ScopeProvider>(); // implements both IScopeProvider and IScopeAccessor builder.Services.AddSingleton <IScopeProvider>(f => f.GetRequiredService <ScopeProvider>()); builder.Services.AddSingleton <IScopeAccessor>(f => f.GetRequiredService <ScopeProvider>()); builder.Services.AddScoped <IHttpScopeReference, HttpScopeReference>(); builder.Services.AddSingleton <IJsonSerializer, JsonNetSerializer>(); builder.Services.AddSingleton <IConfigurationEditorJsonSerializer, ConfigurationEditorJsonSerializer>(); builder.Services.AddSingleton <IMenuItemCollectionFactory, MenuItemCollectionFactory>(); // register database builder // *not* a singleton, don't want to keep it around builder.Services.AddTransient <DatabaseBuilder>(); // register manifest parser, will be injected in collection builders where needed builder.Services.AddSingleton <IManifestParser, ManifestParser>(); // register the manifest filter collection builder (collection is empty by default) builder.ManifestFilters(); builder.MediaUrlGenerators() .Add <FileUploadPropertyEditor>() .Add <ImageCropperPropertyEditor>(); builder.Services.AddSingleton <IPublishedContentTypeFactory, PublishedContentTypeFactory>(); builder.Services.AddSingleton <IShortStringHelper>(factory => new DefaultShortStringHelper(new DefaultShortStringHelperConfig().WithDefault(factory.GetRequiredService <IOptions <RequestHandlerSettings> >().Value))); builder.Services.AddSingleton <IMigrationPlanExecutor, MigrationPlanExecutor>(); builder.Services.AddSingleton <IMigrationBuilder>(factory => new MigrationBuilder(factory)); builder.AddPreValueMigrators(); builder.Services.AddSingleton <IPublishedSnapshotRebuilder, PublishedSnapshotRebuilder>(); // register the published snapshot accessor - the "current" published snapshot is in the umbraco context builder.Services.AddSingleton <IPublishedSnapshotAccessor, UmbracoContextPublishedSnapshotAccessor>(); builder.Services.AddSingleton <IVariationContextAccessor, HybridVariationContextAccessor>(); // Config manipulator builder.Services.AddSingleton <IConfigManipulator, JsonConfigManipulator>(); builder.Services.AddSingleton <RichTextEditorPastedImages>(); builder.Services.AddSingleton <BlockEditorConverter>(); // both TinyMceValueConverter (in Core) and RteMacroRenderingValueConverter (in Web) will be // discovered when CoreBootManager configures the converters. We will remove the basic one defined // in core so that the more enhanced version is active. builder.PropertyValueConverters() .Remove <SimpleTinyMceValueConverter>(); // register *all* checks, except those marked [HideFromTypeFinder] of course builder.Services.AddSingleton <IMarkdownToHtmlConverter, MarkdownToHtmlConverter>(); builder.Services.AddSingleton <IContentLastChanceFinder, ContentFinderByConfigured404>(); builder.Services.AddScoped <UmbracoTreeSearcher>(); // replace builder.Services.AddSingleton <IEmailSender, EmailSender>( services => new EmailSender( services.GetRequiredService <ILogger <EmailSender> >(), services.GetRequiredService <IOptions <GlobalSettings> >(), services.GetRequiredService <IEventAggregator>(), services.GetService <INotificationHandler <SendEmailNotification> >(), services.GetService <INotificationAsyncHandler <SendEmailNotification> >())); builder.Services.AddSingleton <IExamineManager, ExamineManager>(); builder.Services.AddScoped <ITagQuery, TagQuery>(); builder.Services.AddSingleton <IUmbracoTreeSearcherFields, UmbracoTreeSearcherFields>(); builder.Services.AddSingleton <IPublishedContentQueryAccessor, PublishedContentQueryAccessor>(); builder.Services.AddScoped <IPublishedContentQuery>(factory => { var umbCtx = factory.GetRequiredService <IUmbracoContextAccessor>(); var umbracoContext = umbCtx.GetRequiredUmbracoContext(); return(new PublishedContentQuery(umbracoContext.PublishedSnapshot, factory.GetRequiredService <IVariationContextAccessor>(), factory.GetRequiredService <IExamineManager>())); }); // register accessors for cultures builder.Services.AddSingleton <IDefaultCultureAccessor, DefaultCultureAccessor>(); builder.Services.AddSingleton <IFilePermissionHelper, FilePermissionHelper>(); builder.Services.AddSingleton <IUmbracoComponentRenderer, UmbracoComponentRenderer>(); builder.Services.AddSingleton <IBackOfficeExamineSearcher, NoopBackOfficeExamineSearcher>(); builder.Services.AddSingleton <UploadAutoFillProperties>(); builder.Services.AddSingleton <ICronTabParser, NCronTabParser>(); // Add default ImageSharp configuration and service implementations builder.Services.AddSingleton(SixLabors.ImageSharp.Configuration.Default); builder.Services.AddSingleton <IImageDimensionExtractor, ImageSharpDimensionExtractor>(); builder.Services.AddSingleton <IImageUrlGenerator, ImageSharpImageUrlGenerator>(); builder.Services.AddSingleton <PackageDataInstallation>(); builder.AddInstaller(); // Services required to run background jobs (with out the handler) builder.Services.AddSingleton <IBackgroundTaskQueue, BackgroundTaskQueue>(); return(builder); }
/// <summary> /// Adds all core collection builders /// </summary> internal static void AddAllCoreCollectionBuilders(this IUmbracoBuilder builder) { builder.CacheRefreshers()?.Add(() => builder.TypeLoader.GetCacheRefreshers()); builder.DataEditors()?.Add(() => builder.TypeLoader.GetDataEditors()); builder.Actions()?.Add(() => builder.TypeLoader.GetActions()); // register known content apps builder.ContentApps()? .Append <ListViewContentAppFactory>() .Append <ContentEditorContentAppFactory>() .Append <ContentInfoContentAppFactory>() .Append <ContentTypeDesignContentAppFactory>() .Append <ContentTypeListViewContentAppFactory>() .Append <ContentTypePermissionsContentAppFactory>() .Append <ContentTypeTemplatesContentAppFactory>() .Append <MemberEditorContentAppFactory>() .Append <DictionaryContentAppFactory>(); // all built-in finders in the correct order, // devs can then modify this list on application startup builder.ContentFinders()? .Append <ContentFinderByPageIdQuery>() .Append <ContentFinderByUrl>() .Append <ContentFinderByIdPath>() /*.Append<ContentFinderByUrlAndTemplate>() // disabled, this is an odd finder */ .Append <ContentFinderByUrlAlias>() .Append <ContentFinderByRedirectUrl>(); builder.EditorValidators()?.Add(() => builder.TypeLoader.GetTypes <IEditorValidator>()); builder.HealthChecks()?.Add(() => builder.TypeLoader.GetTypes <HealthCheck>()); builder.HealthCheckNotificationMethods()?.Add(() => builder.TypeLoader.GetTypes <IHealthCheckNotificationMethod>()); builder.TourFilters(); builder.UrlProviders()? .Append <AliasUrlProvider>() .Append <DefaultUrlProvider>(); builder.MediaUrlProviders()? .Append <DefaultMediaUrlProvider>(); // register back office sections in the order we want them rendered builder.Sections()? .Append <ContentSection>() .Append <MediaSection>() .Append <SettingsSection>() .Append <PackagesSection>() .Append <UsersSection>() .Append <MembersSection>() .Append <FormsSection>() .Append <TranslationSection>(); builder.Components(); // register core CMS dashboards and 3rd party types - will be ordered by weight attribute & merged with package.manifest dashboards builder.Dashboards()? .Add <ContentDashboard>() .Add <ExamineDashboard>() .Add <FormsDashboard>() .Add <HealthCheckDashboard>() .Add <ManifestDashboard>() .Add <MediaDashboard>() .Add <MembersDashboard>() .Add <ProfilerDashboard>() .Add <PublishedStatusDashboard>() .Add <RedirectUrlDashboard>() .Add <SettingsDashboard>() .Add(builder.TypeLoader.GetTypes <IDashboard>()); builder.DataValueReferenceFactories(); builder.PropertyValueConverters()?.Append(builder.TypeLoader.GetTypes <IPropertyValueConverter>()); builder.UrlSegmentProviders()?.Append <DefaultUrlSegmentProvider>(); builder.ManifestValueValidators()? .Add <RequiredValidator>() .Add <RegexValidator>() .Add <DelimitedValueValidator>() .Add <EmailValidator>() .Add <IntegerValidator>() .Add <DecimalValidator>(); builder.ManifestFilters(); builder.MediaUrlGenerators(); // register OEmbed providers - no type scanning - all explicit opt-in of adding types, IEmbedProvider is not IDiscoverable builder.EmbedProviders()? .Append <YouTube>() .Append <Twitter>() .Append <Vimeo>() .Append <DailyMotion>() .Append <Flickr>() .Append <Slideshare>() .Append <Kickstarter>() .Append <GettyImages>() .Append <Ted>() .Append <Soundcloud>() .Append <Issuu>() .Append <Hulu>() .Append <Giphy>() .Append <LottieFiles>(); builder.SearchableTrees()?.Add(() => builder.TypeLoader.GetTypes <ISearchableTree>()); builder.BackOfficeAssets(); }