public void Compose(IUmbracoBuilder builder)
        {
            builder.Services.AddUnique <RedirectsServiceDependencies>();
            builder.Services.AddUnique <RedirectsBackOfficeHelperDependencies>();

            builder.Services.AddUnique <IRedirectsService, RedirectsService>();
            builder.Services.AddUnique <RedirectsBackOfficeHelper>();

            builder.ContentApps().Append <RedirectsContentAppFactory>();

            builder.AddNotificationHandler <ServerVariablesParsingNotification, ServerVariablesParsingHandler>();
            builder.AddNotificationHandler <UmbracoApplicationStartingNotification, UmbracoApplicationStartingHandler>();

            builder.Services.Configure <UmbracoPipelineOptions>(options => {
                options.AddFilter(new UmbracoPipelineFilter(
                                      "SkybrudRedirects",
                                      _ => { },
                                      applicationBuilder => {
                    applicationBuilder.UseMiddleware <RedirectsMiddleware>();
                },
                                      _ => { }
                                      ));
            });

            builder.DataValueReferenceFactories().Append <OutboundRedirectReferenceFactory>();
        }
        protected override void CustomTestSetup(IUmbracoBuilder builder)
        {
            base.CustomTestSetup(builder);

            builder.AddNotificationHandler <ContentSavingNotification, TestContentNotificationHandler>();
            builder.AddNotificationHandler <ContentTypeSavingNotification, TestContentTypeNotificationHandler>();
            builder.AddNotificationHandler <MediaSavedNotification, TestMediaNotificationHandler>();
        }
Exemple #3
0
        /// <summary>
        ///  Add uSync to the site.
        /// </summary>
        public static IUmbracoBuilder AdduSync(this IUmbracoBuilder builder, Action <uSyncSettings> defaultOptions = default)
        {
            // if the uSyncConfig Service is registred then we assume this has been added before so we don't do it again.
            if (builder.Services.FirstOrDefault(x => x.ServiceType == typeof(uSyncConfigService)) != null)
            {
                return(builder);
            }

            // load up the settings.
            var options = builder.Services.AddOptions <uSyncSettings>()
                          .Bind(builder.Config.GetSection(uSync.Configuration.ConfigSettings));

            if (defaultOptions != default)
            {
                options.Configure(defaultOptions);
            }
            options.ValidateDataAnnotations();

            // default handler options, other people can load their own names handler options and
            // they can be used throughout uSync (so complete will do this).
            var handlerOptiosn = builder.Services.Configure <uSyncHandlerSetSettings>(uSync.Sets.DefaultSet,
                                                                                      builder.Config.GetSection(uSync.Configuration.ConfigDefaultSet));


            // Setup uSync core.
            builder.AdduSyncCore();


            // Setup the back office.
            builder.Services.AddSingleton <uSyncEventService>();
            builder.Services.AddSingleton <uSyncConfigService>();
            builder.Services.AddSingleton <SyncFileService>();

            builder.WithCollectionBuilder <SyncHandlerCollectionBuilder>()
            .Add(() => builder.TypeLoader.GetTypes <ISyncHandler>());

            builder.Services.AddSingleton <SyncHandlerFactory>();
            builder.Services.AddSingleton <uSyncService>();
            builder.Services.AddSingleton <CacheLifecycleManager>();

            // first boot should happen before any other bits of uSync export on a blank site.
            builder.AdduSyncFirstBoot();

            // register for the notifications
            builder.AddNotificationHandler <ServerVariablesParsingNotification, uSyncServerVariablesHandler>();
            builder.AddNotificationHandler <UmbracoApplicationStartedNotification, uSyncApplicationStartingHandler>();
            builder.AddHandlerNotifications();

            builder.Services.AddSingleton <uSyncHubRoutes>();
            builder.Services.AddSignalR();
            builder.Services.AdduSyncSignalR();

            builder.Services.AddAuthorization(o => CreatePolicies(o));


            return(builder);
        }
 /// <summary>
 ///     Adds distributed cache support
 /// </summary>
 /// <remarks>
 ///     This is still required for websites that are not load balancing because this ensures that sites hosted
 ///     with managed hosts like IIS/etc... work correctly when AppDomains are running in parallel.
 /// </remarks>
 public static IUmbracoBuilder AddDistributedCache(this IUmbracoBuilder builder)
 {
     builder.Services.AddSingleton <LastSyncedFileManager>();
     builder.Services.AddSingleton <ISyncBootStateAccessor, SyncBootStateAccessor>();
     builder.SetServerMessenger <BatchedDatabaseServerMessenger>();
     builder.AddNotificationHandler <UmbracoApplicationStartingNotification, DatabaseServerMessengerNotificationHandler>();
     builder.AddNotificationHandler <UmbracoRequestEndNotification, DatabaseServerMessengerNotificationHandler>();
     return(builder);
 }
Exemple #5
0
        /// <summary>
        /// Adds umbraco's embedded model builder support
        /// </summary>
        public static IUmbracoBuilder AddModelsBuilder(this IUmbracoBuilder builder)
        {
            var umbServices = new UniqueServiceDescriptor(typeof(UmbracoServices), typeof(UmbracoServices), ServiceLifetime.Singleton);

            if (builder.Services.Contains(umbServices))
            {
                // if this ext method is called more than once just exit
                return(builder);
            }

            builder.Services.Add(umbServices);

            builder.AddInMemoryModelsRazorEngine();

            // TODO: I feel like we could just do builder.AddNotificationHandler<ModelsBuilderNotificationHandler>() and it
            // would automatically just register for all implemented INotificationHandler{T}?
            builder.AddNotificationHandler <TemplateSavingNotification, ModelsBuilderNotificationHandler>();
            builder.AddNotificationHandler <ServerVariablesParsingNotification, ModelsBuilderNotificationHandler>();
            builder.AddNotificationHandler <ModelBindingErrorNotification, ModelsBuilderNotificationHandler>();
            builder.AddNotificationHandler <UmbracoApplicationStartingNotification, AutoModelsNotificationHandler>();
            builder.AddNotificationHandler <UmbracoRequestEndNotification, AutoModelsNotificationHandler>();
            builder.AddNotificationHandler <ContentTypeCacheRefresherNotification, AutoModelsNotificationHandler>();
            builder.AddNotificationHandler <DataTypeCacheRefresherNotification, AutoModelsNotificationHandler>();

            builder.Services.AddSingleton <ModelsGenerator>();
            builder.Services.AddSingleton <OutOfDateModelsStatus>();
            builder.AddNotificationHandler <ContentTypeCacheRefresherNotification, OutOfDateModelsStatus>();
            builder.AddNotificationHandler <DataTypeCacheRefresherNotification, OutOfDateModelsStatus>();
            builder.Services.AddSingleton <ModelsGenerationError>();

            builder.Services.AddSingleton <InMemoryModelFactory>();

            // This is what the community MB would replace, all of the above services are fine to be registered
            // even if the community MB is in place.
            builder.Services.AddSingleton <IPublishedModelFactory>(factory =>
            {
                ModelsBuilderSettings config = factory.GetRequiredService <IOptions <ModelsBuilderSettings> >().Value;
                if (config.ModelsMode == ModelsMode.InMemoryAuto)
                {
                    return(factory.GetRequiredService <InMemoryModelFactory>());
                }
                else
                {
                    return(factory.CreateDefaultPublishedModelFactory());
                }
            });


            if (!builder.Services.Any(x => x.ServiceType == typeof(IModelsBuilderDashboardProvider)))
            {
                builder.Services.AddUnique <IModelsBuilderDashboardProvider, NoopModelsBuilderDashboardProvider>();
            }

            return(builder);
        }
    public async Task CanPublishEvents()
    {
        _builder.Services.AddScoped <Adder>();
        _builder.AddNotificationHandler <Notification, NotificationHandlerA>();
        _builder.AddNotificationHandler <Notification, NotificationHandlerB>();
        _builder.AddNotificationHandler <Notification, NotificationHandlerC>();
        var provider = _builder.Services.BuildServiceProvider();

        var notification = new Notification();
        var aggregator   = provider.GetService <IEventAggregator>();
        await aggregator.PublishAsync(notification);

        Assert.AreEqual(A + B + C, notification.SubscriberCount);
    }
Exemple #7
0
        public static IUmbracoBuilder AdduSyncAutoTemplates(this IUmbracoBuilder builder)
        {
            // check to see if we've been registerd before.
            if (builder.Services.FindIndex(x => x.ServiceType == typeof(TemplateWatcher)) != -1)
            {
                return(builder);
            }

            builder.Services.AddSingleton <TemplateWatcher>();
            builder.AddNotificationHandler <UmbracoApplicationStartingNotification, AutoTemplateNotificationHandler>();
            builder.AddNotificationHandler <TemplateSavingNotification, AutoTemplateNotificationHandler>();

            return(builder);
        }
 protected override void CustomTestSetup(IUmbracoBuilder builder)
 {
     builder.AddNuCache();
     builder.Services.AddUnique <IServerMessenger, LocalServerMessenger>();
     builder
     .AddNotificationHandler <DictionaryItemDeletedNotification, DistributedCacheBinder>()
     .AddNotificationHandler <DictionaryItemSavedNotification, DistributedCacheBinder>()
     .AddNotificationHandler <LanguageSavedNotification, DistributedCacheBinder>()
     .AddNotificationHandler <LanguageDeletedNotification, DistributedCacheBinder>()
     .AddNotificationHandler <UserSavedNotification, DistributedCacheBinder>()
     .AddNotificationHandler <LanguageDeletedNotification, DistributedCacheBinder>()
     .AddNotificationHandler <MemberGroupDeletedNotification, DistributedCacheBinder>()
     .AddNotificationHandler <MemberGroupSavedNotification, DistributedCacheBinder>();
     builder.AddNotificationHandler <LanguageSavedNotification, PublishedSnapshotServiceEventHandler>();
 }
 protected override void CustomTestSetup(IUmbracoBuilder builder) => builder
 .AddNotificationHandler <ContentSavingNotification, ContentNotificationHandler>()
 .AddNotificationHandler <ContentSavedNotification, ContentNotificationHandler>()
 .AddNotificationHandler <ContentPublishingNotification, ContentNotificationHandler>()
 .AddNotificationHandler <ContentPublishedNotification, ContentNotificationHandler>()
 .AddNotificationHandler <ContentUnpublishingNotification, ContentNotificationHandler>()
 .AddNotificationHandler <ContentUnpublishedNotification, ContentNotificationHandler>();
Exemple #10
0
        public static IUmbracoBuilder AddVendrReviews(this IUmbracoBuilder builder, Action <VendrReviewsSettings> defaultOptions = default)
        {
            // Register configuration
            var options = builder.Services.AddOptions <VendrReviewsSettings>()
                          .Bind(builder.Config.GetSection(Constants.System.ProductName));

            if (defaultOptions != default)
            {
                options.Configure(defaultOptions);
            }

            options.ValidateDataAnnotations();

            // Register services
            builder.Services.AddTransient <IReviewRepositoryFactory, ReviewRepositoryFactory>();
            builder.Services.AddSingleton <IReviewService, ReviewService>();
            builder.Services.AddSingleton <VendrReviewsApi>();

            // Register event handlers
#if NET
            builder.AddNotificationHandler <TreeNodesRenderingNotification, ReviewsTreeNodesNotification>();
#endif
            builder.AddVendrReviewsEventHandlers();

            // Register component
            builder.Components()
            .Append <VendrReviewsComponent>();

            return(builder);
        }
        /// <summary>
        /// Adds Identity support for Umbraco members
        /// </summary>
        public static IUmbracoBuilder AddMembersIdentity(this IUmbracoBuilder builder)
        {
            IServiceCollection services = builder.Services;

            // check if this has already been added, we cannot add twice but both front-end and back end
            // depend on this so it's possible it can be called twice.
            var distCacheBinder = new UniqueServiceDescriptor(typeof(IMemberManager), typeof(MemberManager), ServiceLifetime.Scoped);

            if (builder.Services.Contains(distCacheBinder))
            {
                return(builder);
            }

            // NOTE: We are using AddIdentity which is going to add all of the default AuthN/AuthZ configurations = OK!
            // This will also add all of the default identity services for our user/role types that we aren't overriding = OK!
            // If a developer wishes to use Umbraco Members with different AuthN/AuthZ values, like different cookie values
            // or authentication scheme's then they can call the default identity configuration methods like ConfigureApplicationCookie.
            // BUT ... if a developer wishes to use the default auth schemes for entirely separate purposes alongside Umbraco members,
            // then we'll probably have to change this and make it more flexible like how we do for Users. Which means booting up
            // identity here with the basics and registering all of our own custom services.
            // Since we are using the defaults in v8 (and below) for members, I think using the default for members now is OK!

            services.AddIdentity <MemberIdentityUser, UmbracoIdentityRole>()
            .AddDefaultTokenProviders()
            .AddUserStore <IUserStore <MemberIdentityUser>, MemberUserStore>(factory => new MemberUserStore(
                                                                                 factory.GetRequiredService <IMemberService>(),
                                                                                 factory.GetRequiredService <IUmbracoMapper>(),
                                                                                 factory.GetRequiredService <IScopeProvider>(),
                                                                                 factory.GetRequiredService <IdentityErrorDescriber>(),
                                                                                 factory.GetRequiredService <IPublishedSnapshotAccessor>(),
                                                                                 factory.GetRequiredService <IExternalLoginWithKeyService>(),
                                                                                 factory.GetRequiredService <ITwoFactorLoginService>()
                                                                                 ))
            .AddRoleStore <MemberRoleStore>()
            .AddRoleManager <IMemberRoleManager, MemberRoleManager>()
            .AddMemberManager <IMemberManager, MemberManager>()
            .AddSignInManager <IMemberSignInManager, MemberSignInManager>()
            .AddSignInManager <IMemberSignInManagerExternalLogins, MemberSignInManager>()
            .AddErrorDescriber <MembersErrorDescriber>()
            .AddUserConfirmation <UmbracoUserConfirmation <MemberIdentityUser> >();


            builder.AddNotificationHandler <MemberDeletedNotification, DeleteExternalLoginsOnMemberDeletedHandler>();
            builder.AddNotificationAsyncHandler <MemberDeletedNotification, DeleteTwoFactorLoginsOnMemberDeletedHandler>();
            services.ConfigureOptions <ConfigureMemberIdentityOptions>();

            services.AddScoped <IMemberUserStore>(x => (IMemberUserStore)x.GetRequiredService <IUserStore <MemberIdentityUser> >());
            services.AddScoped <IPasswordHasher <MemberIdentityUser>, MemberPasswordHasher>();

            services.ConfigureOptions <ConfigureSecurityStampOptions>();
            services.ConfigureOptions <ConfigureMemberCookieOptions>();

            services.AddUnique <IMemberExternalLoginProviders, MemberExternalLoginProviders>();

            return(builder);
        }
Exemple #12
0
 protected override void CustomTestSetup(IUmbracoBuilder builder)
 {
     NotificationHandler.PublishedContent = notification => { };
     builder.Services.AddUnique <IServerMessenger, ScopedRepositoryTests.LocalServerMessenger>();
     builder.AddCoreNotifications();
     builder.AddNotificationHandler <ContentPublishedNotification, NotificationHandler>();
     builder.Services.AddUnique <IUmbracoContextAccessor, TestUmbracoContextAccessor>();
     builder.Services.AddUnique(MockHttpContextAccessor.Object);
     builder.AddNuCache();
 }
        public void Compose(IUmbracoBuilder builder)
        {
            builder.MapDefinitions().Add <MemberListItemMapDefinition>();

            builder.Components().Append <MemberIndexingComponent>();
            builder.AddNotificationHandler <ServerVariablesParsingNotification, ServerVariablesParsingHandler>();

            builder.Services.AddUnique <IMemberExtendedService, MemberExtendedService>();

            // Extend the Member Index fieldset.
            builder.Services.ConfigureOptions <ConfigureMemberIndexOptions>();
        }
    /// <summary>
    ///     Adds umbraco's embedded model builder support
    /// </summary>
    public static IUmbracoBuilder AddModelsBuilder(this IUmbracoBuilder builder)
    {
        var umbServices = new UniqueServiceDescriptor(typeof(UmbracoServices), typeof(UmbracoServices), ServiceLifetime.Singleton);

        if (builder.Services.Contains(umbServices))
        {
            // if this ext method is called more than once just exit
            return(builder);
        }

        builder.Services.Add(umbServices);

        if (builder.Config.GetRuntimeMode() == RuntimeMode.BackofficeDevelopment)
        {
            // Configure services to allow InMemoryAuto mode
            builder.AddInMemoryModelsRazorEngine();

            builder.AddNotificationHandler <ModelBindingErrorNotification, ModelsBuilderNotificationHandler>();
            builder.AddNotificationHandler <ContentTypeCacheRefresherNotification, OutOfDateModelsStatus>();
            builder.AddNotificationHandler <DataTypeCacheRefresherNotification, OutOfDateModelsStatus>();
        }

        if (builder.Config.GetRuntimeMode() != RuntimeMode.Production)
        {
            // Configure service to allow models generation
            builder.AddNotificationHandler <ServerVariablesParsingNotification, ModelsBuilderNotificationHandler>();
            builder.AddNotificationHandler <TemplateSavingNotification, ModelsBuilderNotificationHandler>();

            builder.AddNotificationHandler <UmbracoApplicationStartingNotification, AutoModelsNotificationHandler>();
            builder.AddNotificationHandler <UmbracoRequestEndNotification, AutoModelsNotificationHandler>();
            builder.AddNotificationHandler <ContentTypeCacheRefresherNotification, AutoModelsNotificationHandler>();
            builder.AddNotificationHandler <DataTypeCacheRefresherNotification, AutoModelsNotificationHandler>();
        }

        builder.Services.TryAddSingleton <IModelsBuilderDashboardProvider, NoopModelsBuilderDashboardProvider>();

        // Register required services for ModelsBuilderDashboardController
        builder.Services.AddSingleton <ModelsGenerator>();
        builder.Services.AddSingleton <OutOfDateModelsStatus>();
        builder.Services.AddSingleton <ModelsGenerationError>();

        return(builder);
    }
Exemple #15
0
        public static IUmbracoBuilder AdduSyncFirstBoot(this IUmbracoBuilder builder)
        {
            builder.Services.PostConfigure <GlobalSettings>(settings =>
            {
                if (settings.NoNodesViewPath.InvariantEquals(defaultNoNodesPath))
                {
                    // if the default hasn't changed, put in the uSync version
                    settings.NoNodesViewPath = noNodesPath;
                }
            });

            // add notification handler to do the actual first boot run.
            builder.AddNotificationHandler <UmbracoApplicationStartingNotification, FirstBootAppStartingHandler>();

            return(builder);
        }
Exemple #16
0
        /// <summary>
        /// Adds the Umbraco request profiler
        /// </summary>
        public static IUmbracoBuilder AddUmbracoProfiler(this IUmbracoBuilder builder)
        {
            builder.Services.AddSingleton <WebProfilerHtml>();

            builder.Services.AddMiniProfiler(options =>
            {
                // WebProfiler determine and start profiling. We should not use the MiniProfilerMiddleware to also profile
                options.ShouldProfile = request => false;

                // this is a default path and by default it performs a 'contains' check which will match our content controller
                // (and probably other requests) and ignore them.
                options.IgnoredPaths.Remove("/content/");
            });

            builder.AddNotificationHandler <UmbracoApplicationStartingNotification, InitializeWebProfiling>();
            return(builder);
        }
    private static IUmbracoBuilder AddNuCacheNotifications(this IUmbracoBuilder builder)
    {
        builder
        .AddNotificationHandler <LanguageSavedNotification, PublishedSnapshotServiceEventHandler>()
        .AddNotificationHandler <MemberDeletingNotification, PublishedSnapshotServiceEventHandler>()
#pragma warning disable CS0618 // Type or member is obsolete
        .AddNotificationHandler <ContentRefreshNotification, PublishedSnapshotServiceEventHandler>()
        .AddNotificationHandler <MediaRefreshNotification, PublishedSnapshotServiceEventHandler>()
        .AddNotificationHandler <MemberRefreshNotification, PublishedSnapshotServiceEventHandler>()
        .AddNotificationHandler <ContentTypeRefreshedNotification, PublishedSnapshotServiceEventHandler>()
        .AddNotificationHandler <MediaTypeRefreshedNotification, PublishedSnapshotServiceEventHandler>()
        .AddNotificationHandler <MemberTypeRefreshedNotification, PublishedSnapshotServiceEventHandler>()
        .AddNotificationHandler <ScopedEntityRemoveNotification, PublishedSnapshotServiceEventHandler>()
#pragma warning restore CS0618 // Type or member is obsolete
        ;

        return(builder);
    }
    /// <summary>
    ///     Adds Umbraco back office authentication requirements
    /// </summary>
    public static IUmbracoBuilder AddBackOfficeAuthentication(this IUmbracoBuilder builder)
    {
        builder.Services

        // This just creates a builder, nothing more
        .AddAuthentication()

        // Add our custom schemes which are cookie handlers
        .AddCookie(Constants.Security.BackOfficeAuthenticationType)
        .AddCookie(Constants.Security.BackOfficeExternalAuthenticationType, o =>
        {
            o.Cookie.Name    = Constants.Security.BackOfficeExternalAuthenticationType;
            o.ExpireTimeSpan = TimeSpan.FromMinutes(5);
        })

        // Although we don't natively support this, we add it anyways so that if end-users implement the required logic
        // they don't have to worry about manually adding this scheme or modifying the sign in manager
        .AddCookie(Constants.Security.BackOfficeTwoFactorAuthenticationType, o =>
        {
            o.Cookie.Name    = Constants.Security.BackOfficeTwoFactorAuthenticationType;
            o.ExpireTimeSpan = TimeSpan.FromMinutes(5);
        })
        .AddCookie(Constants.Security.BackOfficeTwoFactorRememberMeAuthenticationType, o =>
        {
            o.Cookie.Name    = Constants.Security.BackOfficeTwoFactorRememberMeAuthenticationType;
            o.ExpireTimeSpan = TimeSpan.FromMinutes(5);
        });

        builder.Services.ConfigureOptions <ConfigureBackOfficeCookieOptions>();

        builder.Services.AddSingleton <BackOfficeExternalLoginProviderErrorMiddleware>();

        builder.Services.AddUnique <IBackOfficeAntiforgery, BackOfficeAntiforgery>();
        builder.Services.AddUnique <IPasswordChanger <BackOfficeIdentityUser>, PasswordChanger <BackOfficeIdentityUser> >();
        builder.Services.AddUnique <IPasswordChanger <MemberIdentityUser>, PasswordChanger <MemberIdentityUser> >();

        builder.AddNotificationHandler <UserLoginSuccessNotification, BackOfficeUserManagerAuditer>();
        builder.AddNotificationHandler <UserLogoutSuccessNotification, BackOfficeUserManagerAuditer>();
        builder.AddNotificationHandler <UserLoginFailedNotification, BackOfficeUserManagerAuditer>();
        builder.AddNotificationHandler <UserForgotPasswordRequestedNotification, BackOfficeUserManagerAuditer>();
        builder.AddNotificationHandler <UserForgotPasswordChangedNotification, BackOfficeUserManagerAuditer>();
        builder.AddNotificationHandler <UserPasswordChangedNotification, BackOfficeUserManagerAuditer>();
        builder.AddNotificationHandler <UserPasswordResetNotification, BackOfficeUserManagerAuditer>();

        return(builder);
    }
Exemple #19
0
        public static IUmbracoBuilder AddVendrCheckout(this IUmbracoBuilder builder, Action <VendrCheckoutSettings> defaultOptions = default)
        {
            // If the Vendr Checkout InstallService is registred then we assume everything is already registered so we don't do it again.
            if (builder.Services.FirstOrDefault(x => x.ServiceType == typeof(InstallService)) != null)
            {
                return(builder);
            }

            // Register configuration
            var options = builder.Services.AddOptions <VendrCheckoutSettings>()
                          .Bind(builder.Config.GetSection(VendrCheckoutConstants.System.ProductName));

            if (defaultOptions != default)
            {
                options.Configure(defaultOptions);
            }

            options.ValidateDataAnnotations();

            // Register event handlers
            builder.AddVendrEventHandlers();

            // Register pipeline
            builder.AddVendrInstallPipeline();

            // Register services
            builder.Services.AddSingleton <InstallService>();

            // Register helpers
            builder.Services.AddSingleton <PathHelper>();

            // Register Umbraco event handlers
            builder.AddNotificationHandler <ContentCacheRefresherNotification, SyncZeroValuePaymentProviderContinueUrl>();

            return(builder);
        }
        public static IUmbracoBuilder AddExamine(this IUmbracoBuilder builder)
        {
            // populators are not a collection: one cannot remove ours, and can only add more
            // the container can inject IEnumerable<IIndexPopulator> and get them all
            builder.Services.AddSingleton <IIndexPopulator, MemberIndexPopulator>();
            builder.Services.AddSingleton <IIndexPopulator, ContentIndexPopulator>();
            builder.Services.AddSingleton <IIndexPopulator, PublishedContentIndexPopulator>();
            builder.Services.AddSingleton <IIndexPopulator, MediaIndexPopulator>();

            builder.Services.AddSingleton <IIndexRebuilder, ExamineIndexRebuilder>();
            builder.Services.AddSingleton <IUmbracoIndexingHandler, ExamineUmbracoIndexingHandler>();
            builder.Services.AddUnique <IUmbracoIndexConfig, UmbracoIndexConfig>();
            builder.Services.AddUnique <IIndexDiagnosticsFactory, IndexDiagnosticsFactory>();
            builder.Services.AddUnique <IPublishedContentValueSetBuilder>(factory =>
                                                                          new ContentValueSetBuilder(
                                                                              factory.GetRequiredService <PropertyEditorCollection>(),
                                                                              factory.GetRequiredService <UrlSegmentProviderCollection>(),
                                                                              factory.GetRequiredService <IUserService>(),
                                                                              factory.GetRequiredService <IShortStringHelper>(),
                                                                              factory.GetRequiredService <IScopeProvider>(),
                                                                              true));
            builder.Services.AddUnique <IContentValueSetBuilder>(factory =>
                                                                 new ContentValueSetBuilder(
                                                                     factory.GetRequiredService <PropertyEditorCollection>(),
                                                                     factory.GetRequiredService <UrlSegmentProviderCollection>(),
                                                                     factory.GetRequiredService <IUserService>(),
                                                                     factory.GetRequiredService <IShortStringHelper>(),
                                                                     factory.GetRequiredService <IScopeProvider>(),
                                                                     false));
            builder.Services.AddUnique <IValueSetBuilder <IMedia>, MediaValueSetBuilder>();
            builder.Services.AddUnique <IValueSetBuilder <IMember>, MemberValueSetBuilder>();
            builder.Services.AddSingleton <ExamineIndexRebuilder>();

            builder.AddNotificationHandler <ContentCacheRefresherNotification, ContentIndexingNotificationHandler>();
            builder.AddNotificationHandler <ContentTypeCacheRefresherNotification, ContentTypeIndexingNotificationHandler>();
            builder.AddNotificationHandler <MediaCacheRefresherNotification, MediaIndexingNotificationHandler>();
            builder.AddNotificationHandler <MemberCacheRefresherNotification, MemberIndexingNotificationHandler>();
            builder.AddNotificationHandler <LanguageCacheRefresherNotification, LanguageIndexingNotificationHandler>();

            builder.AddNotificationHandler <UmbracoRequestBeginNotification, RebuildOnStartupHandler>();

            return(builder);
        }
 protected override void CustomTestSetup(IUmbracoBuilder builder)
 {
     builder.AddNotificationHandler <SendingContentNotification, FilterEventHandler>();
 }
 protected override void CustomTestSetup(IUmbracoBuilder builder) => builder
 .AddNotificationHandler <MediaMovedToRecycleBinNotification, ContentNotificationHandler>();
Exemple #23
0
        internal static void AddHandlerNotifications(this IUmbracoBuilder builder)
        {
            // TODO: Would be nice if we could just register all the notifications in the handlers

            builder.AddNotificationHandler <DataTypeSavedNotification, DataTypeHandler>();
            builder.AddNotificationHandler <DataTypeDeletedNotification, DataTypeHandler>();
            builder.AddNotificationHandler <DataTypeMovedNotification, DataTypeHandler>();
            builder.AddNotificationHandler <EntityContainerSavedNotification, DataTypeHandler>();

            builder.AddNotificationHandler <ContentTypeSavedNotification, ContentTypeHandler>();
            builder.AddNotificationHandler <ContentTypeDeletedNotification, ContentTypeHandler>();
            builder.AddNotificationHandler <ContentTypeMovedNotification, ContentTypeHandler>();
            builder.AddNotificationHandler <EntityContainerSavedNotification, ContentTypeHandler>();

            builder.AddNotificationHandler <MediaTypeSavedNotification, MediaTypeHandler>();
            builder.AddNotificationHandler <MediaTypeDeletedNotification, MediaTypeHandler>();
            builder.AddNotificationHandler <MediaTypeMovedNotification, MediaTypeHandler>();
            builder.AddNotificationHandler <EntityContainerSavedNotification, MediaTypeHandler>();

            builder.AddNotificationHandler <MemberTypeSavedNotification, MemberTypeHandler>();
            builder.AddNotificationHandler <MemberTypeSavedNotification, MemberTypeHandler>();
            builder.AddNotificationHandler <MemberTypeMovedNotification, MemberTypeHandler>();

            builder.AddNotificationHandler <LanguageSavingNotification, LanguageHandler>();
            builder.AddNotificationHandler <LanguageSavedNotification, LanguageHandler>();
            builder.AddNotificationHandler <LanguageDeletedNotification, LanguageHandler>();

            builder.AddNotificationHandler <MacroSavedNotification, MacroHandler>();
            builder.AddNotificationHandler <MacroDeletedNotification, MacroHandler>();

            builder.AddNotificationHandler <TemplateSavedNotification, TemplateHandler>();
            builder.AddNotificationHandler <TemplateDeletedNotification, TemplateHandler>();

            // content ones
            builder.AddNotificationHandler <ContentSavedNotification, ContentHandler>();
            builder.AddNotificationHandler <ContentDeletedNotification, ContentHandler>();
            builder.AddNotificationHandler <ContentMovedNotification, ContentHandler>();
            builder.AddNotificationHandler <ContentMovedToRecycleBinNotification, ContentHandler>();

            builder.AddNotificationHandler <MediaSavedNotification, MediaHandler>();
            builder.AddNotificationHandler <MediaDeletedNotification, MediaHandler>();
            builder.AddNotificationHandler <MediaMovedNotification, MediaHandler>();
            builder.AddNotificationHandler <MediaMovedToRecycleBinNotification, MediaHandler>();

            builder.AddNotificationHandler <DomainSavedNotification, DomainHandler>();
            builder.AddNotificationHandler <DomainDeletedNotification, DomainHandler>();

            builder.AddNotificationHandler <DictionaryItemSavedNotification, DictionaryHandler>();
            builder.AddNotificationHandler <DictionaryItemDeletedNotification, DictionaryHandler>();

            builder.AddNotificationHandler <RelationTypeSavedNotification, RelationTypeHandler>();
            builder.AddNotificationHandler <RelationTypeDeletedNotification, RelationTypeHandler>();

            // builder.AddNotificationHandler<ContentSavedBlueprintNotification, ContentHandler>();
            // builder.AddNotificationHandler<ContentDeletedBlueprintNotification, ContentHandler>();

            // cache lifecylce manager
            builder.
            AddNotificationHandler <uSyncImportStartingNotification, CacheLifecycleManager>().
            AddNotificationHandler <uSyncReportStartingNotification, CacheLifecycleManager>().
            AddNotificationHandler <uSyncExportStartingNotification, CacheLifecycleManager>().
            AddNotificationHandler <uSyncImportCompletedNotification, CacheLifecycleManager>().
            AddNotificationHandler <uSyncReportCompletedNotification, CacheLifecycleManager>().
            AddNotificationHandler <uSyncExportCompletedNotification, CacheLifecycleManager>().
            AddNotificationHandler <ContentSavingNotification, CacheLifecycleManager>().
            AddNotificationHandler <ContentDeletingNotification, CacheLifecycleManager>().
            AddNotificationHandler <ContentMovingNotification, CacheLifecycleManager>().
            AddNotificationHandler <MediaSavingNotification, CacheLifecycleManager>().
            AddNotificationHandler <MediaSavedNotification, CacheLifecycleManager>().
            AddNotificationHandler <MediaDeletedNotification, CacheLifecycleManager>();
        }
        public static IUmbracoBuilder AddCoreNotifications(this IUmbracoBuilder builder)
        {
            // add handlers for sending user notifications (i.e. emails)
            builder.Services.AddSingleton <UserNotificationsHandler.Notifier>();
            builder
            .AddNotificationHandler <ContentSavedNotification, UserNotificationsHandler>()
            .AddNotificationHandler <ContentSortedNotification, UserNotificationsHandler>()
            .AddNotificationHandler <ContentPublishedNotification, UserNotificationsHandler>()
            .AddNotificationHandler <ContentMovedNotification, UserNotificationsHandler>()
            .AddNotificationHandler <ContentMovedToRecycleBinNotification, UserNotificationsHandler>()
            .AddNotificationHandler <ContentCopiedNotification, UserNotificationsHandler>()
            .AddNotificationHandler <ContentRolledBackNotification, UserNotificationsHandler>()
            .AddNotificationHandler <ContentSentToPublishNotification, UserNotificationsHandler>()
            .AddNotificationHandler <ContentUnpublishedNotification, UserNotificationsHandler>()
            .AddNotificationHandler <AssignedUserGroupPermissionsNotification, UserNotificationsHandler>()
            .AddNotificationHandler <PublicAccessEntrySavedNotification, UserNotificationsHandler>();

            // add handlers for building content relations
            builder
            .AddNotificationHandler <ContentCopiedNotification, RelateOnCopyNotificationHandler>()
            .AddNotificationHandler <ContentMovedNotification, RelateOnTrashNotificationHandler>()
            .AddNotificationHandler <ContentMovedToRecycleBinNotification, RelateOnTrashNotificationHandler>()
            .AddNotificationHandler <MediaMovedNotification, RelateOnTrashNotificationHandler>()
            .AddNotificationHandler <MediaMovedToRecycleBinNotification, RelateOnTrashNotificationHandler>();

            // add notification handlers for property editors
            builder
            .AddNotificationHandler <ContentSavingNotification, BlockEditorPropertyHandler>()
            .AddNotificationHandler <ContentCopyingNotification, BlockEditorPropertyHandler>()
            .AddNotificationHandler <ContentSavingNotification, NestedContentPropertyHandler>()
            .AddNotificationHandler <ContentCopyingNotification, NestedContentPropertyHandler>()
            .AddNotificationHandler <ContentCopiedNotification, FileUploadPropertyEditor>()
            .AddNotificationHandler <ContentDeletedNotification, FileUploadPropertyEditor>()
            .AddNotificationHandler <MediaDeletedNotification, FileUploadPropertyEditor>()
            .AddNotificationHandler <MediaSavingNotification, FileUploadPropertyEditor>()
            .AddNotificationHandler <MemberDeletedNotification, FileUploadPropertyEditor>()
            .AddNotificationHandler <ContentCopiedNotification, ImageCropperPropertyEditor>()
            .AddNotificationHandler <ContentDeletedNotification, ImageCropperPropertyEditor>()
            .AddNotificationHandler <MediaDeletedNotification, ImageCropperPropertyEditor>()
            .AddNotificationHandler <MediaSavingNotification, ImageCropperPropertyEditor>()
            .AddNotificationHandler <MemberDeletedNotification, ImageCropperPropertyEditor>();

            // add notification handlers for redirect tracking
            builder
            .AddNotificationHandler <ContentPublishingNotification, RedirectTrackingHandler>()
            .AddNotificationHandler <ContentPublishedNotification, RedirectTrackingHandler>()
            .AddNotificationHandler <ContentMovingNotification, RedirectTrackingHandler>()
            .AddNotificationHandler <ContentMovedNotification, RedirectTrackingHandler>();

            // Add notification handlers for DistributedCache
            builder
            .AddNotificationHandler <DictionaryItemDeletedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <DictionaryItemSavedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <LanguageSavedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <LanguageDeletedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <MemberSavedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <MemberDeletedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <PublicAccessEntrySavedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <PublicAccessEntryDeletedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <UserSavedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <UserDeletedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <UserGroupWithUsersSavedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <UserGroupDeletedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <MemberGroupDeletedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <MemberGroupSavedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <DataTypeDeletedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <DataTypeSavedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <TemplateDeletedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <TemplateSavedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <RelationTypeDeletedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <RelationTypeSavedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <DomainDeletedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <DomainSavedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <MacroSavedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <MacroDeletedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <MediaTreeChangeNotification, DistributedCacheBinder>()
            .AddNotificationHandler <ContentTypeChangedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <MediaTypeChangedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <MemberTypeChangedNotification, DistributedCacheBinder>()
            .AddNotificationHandler <ContentTreeChangeNotification, DistributedCacheBinder>()
            ;
            // add notification handlers for auditing
            builder
            .AddNotificationHandler <MemberSavedNotification, AuditNotificationsHandler>()
            .AddNotificationHandler <MemberDeletedNotification, AuditNotificationsHandler>()
            .AddNotificationHandler <AssignedMemberRolesNotification, AuditNotificationsHandler>()
            .AddNotificationHandler <RemovedMemberRolesNotification, AuditNotificationsHandler>()
            .AddNotificationHandler <ExportedMemberNotification, AuditNotificationsHandler>()
            .AddNotificationHandler <UserSavedNotification, AuditNotificationsHandler>()
            .AddNotificationHandler <UserDeletedNotification, AuditNotificationsHandler>()
            .AddNotificationHandler <UserGroupWithUsersSavedNotification, AuditNotificationsHandler>()
            .AddNotificationHandler <AssignedUserGroupPermissionsNotification, AuditNotificationsHandler>();

            return(builder);
        }
Exemple #25
0
 public void Compose(IUmbracoBuilder builder)
 {
     builder.AddNotificationHandler <ServerVariablesParsingNotification, ConfigTreeNotificatonHandler>();
 }
    /// <summary>
    ///     Adds Umbraco NuCache dependencies
    /// </summary>
    public static IUmbracoBuilder AddNuCache(this IUmbracoBuilder builder)
    {
        // register the NuCache database data source
        builder.Services.TryAddSingleton <INuCacheContentRepository, NuCacheContentRepository>();
        builder.Services.TryAddSingleton <INuCacheContentService, NuCacheContentService>();
        builder.Services.TryAddSingleton <PublishedSnapshotServiceEventHandler>();

        // register the NuCache published snapshot service
        // must register default options, required in the service ctor
        builder.Services.TryAddTransient(factory => new PublishedSnapshotServiceOptions());
        builder.SetPublishedSnapshotService <PublishedSnapshotService>();
        builder.Services.TryAddSingleton <IPublishedSnapshotStatus, PublishedSnapshotStatus>();

        // replace this service since we want to improve the content/media
        // mapping lookups if we are using nucache.
        // TODO: Gotta wonder how much this does actually improve perf? It's a lot of weird code to make this happen so hope it's worth it
        builder.Services.AddUnique <IIdKeyMap>(factory =>
        {
            var idkSvc = new IdKeyMap(
                factory.GetRequiredService <ICoreScopeProvider>(),
                factory.GetRequiredService <IIdKeyMapRepository>());
            if (factory.GetRequiredService <IPublishedSnapshotService>() is PublishedSnapshotService
                publishedSnapshotService)
            {
                idkSvc.SetMapper(UmbracoObjectTypes.Document, id => publishedSnapshotService.GetDocumentUid(id), uid => publishedSnapshotService.GetDocumentId(uid));
                idkSvc.SetMapper(UmbracoObjectTypes.Media, id => publishedSnapshotService.GetMediaUid(id), uid => publishedSnapshotService.GetMediaId(uid));
            }

            return(idkSvc);
        });

        builder.AddNuCacheNotifications();

        builder.AddNotificationHandler <UmbracoApplicationStartingNotification, NuCacheStartupHandler>();
        builder.Services.AddSingleton <IContentCacheDataSerializerFactory>(s =>
        {
            IOptions <NuCacheSettings> options = s.GetRequiredService <IOptions <NuCacheSettings> >();
            switch (options.Value.NuCacheSerializerType)
            {
            case NuCacheSerializerType.JSON:
                return(new JsonContentNestedDataSerializerFactory());

            case NuCacheSerializerType.MessagePack:
                return(ActivatorUtilities.CreateInstance <MsgPackContentNestedDataSerializerFactory>(s));

            default:
                throw new IndexOutOfRangeException();
            }
        });

        builder.Services.AddSingleton <IPropertyCacheCompressionOptions>(s =>
        {
            IOptions <NuCacheSettings> options = s.GetRequiredService <IOptions <NuCacheSettings> >();

            if (options.Value.NuCacheSerializerType == NuCacheSerializerType.MessagePack &&
                options.Value.UnPublishedContentCompression)
            {
                return(new UnPublishedContentPropertyCacheCompressionOptions());
            }

            return(new NoopPropertyCacheCompressionOptions());
        });

        builder.Services.AddSingleton(s => new ContentDataSerializer(new DictionaryOfPropertyDataSerializer()));

        // add the NuCache health check (hidden from type finder)
        // TODO: no NuCache health check yet
        // composition.HealthChecks().Add<NuCacheIntegrityHealthCheck>();
        return(builder);
    }
 public void Compose(IUmbracoBuilder builder)
 {
     builder.AddGoogleMaps();
     builder.AddNotificationHandler <ServerVariablesParsingNotification, ServerVariablesParsingHandler>();
 }
Exemple #28
0
        /// <summary>
        /// Adds all web based services required for Umbraco to run
        /// </summary>
        public static IUmbracoBuilder AddWebComponents(this IUmbracoBuilder builder)
        {
            // Add service session
            // This can be overwritten by the user by adding their own call to AddSession
            // since the last call of AddSession take precedence
            builder.Services.AddSession(options =>
            {
                options.Cookie.Name     = "UMB_SESSION";
                options.Cookie.HttpOnly = true;
            });

            builder.Services.ConfigureOptions <UmbracoMvcConfigureOptions>();
            builder.Services.ConfigureOptions <UmbracoRequestLocalizationOptions>();
            builder.Services.TryAddEnumerable(ServiceDescriptor.Transient <IApplicationModelProvider, UmbracoApiBehaviorApplicationModelProvider>());
            builder.Services.TryAddEnumerable(ServiceDescriptor.Transient <IApplicationModelProvider, BackOfficeApplicationModelProvider>());
            builder.Services.TryAddEnumerable(ServiceDescriptor.Transient <IApplicationModelProvider, VirtualPageApplicationModelProvider>());
            builder.AddUmbracoImageSharp();

            // AspNetCore specific services
            builder.Services.AddUnique <IRequestAccessor, AspNetCoreRequestAccessor>();
            builder.AddNotificationHandler <UmbracoRequestBeginNotification, AspNetCoreRequestAccessor>();

            // Password hasher
            builder.Services.AddUnique <IPasswordHasher, AspNetCorePasswordHasher>();

            builder.Services.AddUnique <Cms.Core.Web.ICookieManager, AspNetCoreCookieManager>();
            builder.Services.AddTransient <IIpResolver, AspNetCoreIpResolver>();
            builder.Services.AddUnique <IUserAgentProvider, AspNetCoreUserAgentProvider>();

            builder.Services.AddMultipleUnique <ISessionIdResolver, ISessionManager, AspNetCoreSessionManager>();

            builder.Services.AddUnique <IMarchal, AspNetCoreMarchal>();

            builder.Services.AddUnique <IProfilerHtml, WebProfilerHtml>();

            builder.Services.AddUnique <IMacroRenderer, MacroRenderer>();
            builder.Services.AddSingleton <PartialViewMacroEngine>();

            // register the umbraco context factory

            builder.Services.AddUnique <IUmbracoContextFactory, UmbracoContextFactory>();
            builder.Services.AddUnique <IBackOfficeSecurityAccessor, BackOfficeSecurityAccessor>();

            var umbracoApiControllerTypes = builder.TypeLoader.GetUmbracoApiControllers().ToList();

            builder.WithCollectionBuilder <UmbracoApiControllerTypeCollectionBuilder>()?
            .Add(umbracoApiControllerTypes);

            builder.Services.AddSingleton <UmbracoRequestLoggingMiddleware>();
            builder.Services.AddSingleton <PreviewAuthenticationMiddleware>();
            builder.Services.AddSingleton <UmbracoRequestMiddleware>();
            builder.Services.AddSingleton <BootFailedMiddleware>();

            builder.Services.AddSingleton <UmbracoJsonModelBinder>();

            builder.Services.AddUnique <ITemplateRenderer, TemplateRenderer>();
            builder.Services.AddUnique <IPublicAccessChecker, PublicAccessChecker>();

            builder.Services.AddSingleton <ContentModelBinder>();

            builder.Services.AddSingleton <IUmbracoHelperAccessor, UmbracoHelperAccessor>();
            builder.Services.AddSingleton <IScopedServiceProvider, ScopedServiceProvider>();
            builder.Services.AddScoped <UmbracoHelper>();
            builder.Services.AddScoped <IBackOfficeSecurity, BackOfficeSecurity>();

            builder.AddHttpClients();

            return(builder);
        }
 /// <summary>
 /// Can be called if using an external models builder to remove the embedded models builder controller features.
 /// </summary>
 public static IUmbracoBuilder DisableModelsBuilderControllers(this IUmbracoBuilder builder)
 => builder.AddNotificationHandler <UmbracoApplicationStartingNotification, DisableModelsBuilderNotificationHandler>();