Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • dev-thandabantu 41 posts 321 karma points
    Sep 13, 2022 @ 06:01
    dev-thandabantu
    0

    Register FormValidateNotification handler in startup pipeline

    Hi,

    Kindly asking for help registering handler in my startup pipeline as per the documentation on "Form validation notification". The documentation says:

    To register the handler, add the following code into the startup pipeline. In this example, the registration is implemented as an extension method to IUmbracoBuilder and should be called from Startup.cs

    But when I add the code to my startup, I get two issues:

    1. "extension method must be defined in a non-generic static class": Startup error
    2. "Not all code paths return a value": Error 2

    When I make my startup class static, that creates more errors on my declared variables.

    Thank you.

  • dev-thandabantu 41 posts 321 karma points
    Sep 13, 2022 @ 10:14
    dev-thandabantu
    100

    To fix this issue, add the extension method in a separate static class e.g

    public static class FormValidationExtension
    {
            public static IUmbracoBuilder AddUmbracoFormsCoreProviders(this IUmbracoBuilder builder) => builder.AddNotificationHandler<FormValidateNotification, FormValidateNotificationHandler>();
    }
    

    Note that in the code above, I have modified the method into an expression to remove the "not all code paths return a value" error.

    Then, in the Startup.cs file, add the following:

    public void ConfigureServices(IServiceCollection services)
    {
                services.AddUmbraco(_env, _config)
                    .AddBackOffice()
                    .AddAzureADBackofficeAuthentication()
                    .AddWebsite()
                    .AddComposers()
                    .AddAzureBlobMediaFileSystem()
                    .AddUmbracoFormsCoreProviders()
                    .Build();
    }
    

    Note the AddUmbracoFormsCoreProviders()

    That should resolve the issue.

Please Sign in or register to post replies

Write your reply to:

Draft