Copied to clipboard

Flag this post as spam?

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


  • Kevin Jump 2348 posts 14896 karma points MVP 8x c-trib
    Apr 23, 2021 @ 12:24
    Kevin Jump
    0

    How to add/alter routes/enpoints without changing startup.cs

    Hi,

    I have a package that uses SignalR to offer nice progress UI.

    porting this to Umbraco 9 - i have seen that you need to register the endpoint for signalR (as perview does here https://github.com/umbraco/Umbraco-CMS/blob/netcore/dev/src/Umbraco.Web.BackOffice/Extensions/UmbracoApplicationBuilder.Preview.cs)

    However enpoints are added on the config element in startup.cs - which i don't think you can hook into other than in the code?

    app.UseUmbraco()
        .WithBackOffice()
        .WithWebsite()
        .WithEndpoints(u =>
        {
            u.UseInstallerEndpoints();
            u.UseBackOfficeEndpoints();
            u.UseWebsiteEndpoints();
        });
    

    so progromatically i can add :

        u.UseuSyncEndpoints();
    

    but i want to be able to also add this route without requiring the user to alter the startup.cs is that possible? can it be done?

  • Bjarke Berg 29 posts 265 karma points hq
    Apr 23, 2021 @ 12:58
    Bjarke Berg
    0

    Hi Kevin..

    I haven't tested it out, but you should be able to do something like this from the composer:

    builder.Services.Configure<UmbracoPipelineOptions>(options =>
                {
                    options.AddFilter(new UmbracoPipelineFilter(
                        "Usync", 
                        applicationBuilder => {},
                        applicationBuilder => {},
                        applicationBuilder =>
                        {
                            // Add your endpoints here..
                        }
                        ));
                });
    

    Let me know if it works (Note this syntax is from the latest nightly, maybe the syntax is different in latest alpha )

  • Kevin Jump 2348 posts 14896 karma points MVP 8x c-trib
    Apr 23, 2021 @ 13:52
    Kevin Jump
    0

    thanks,

    yeah that has worked. 👍 https://github.com/KevinJump/uSync8/blob/core/main/uSync.BackOffice/uSyncBackOfficeBuilderExtensions.cs#L85

    I have a secondary issue in that runtime level doesn't appear to then be set when adding the route (i copied this from how the preview hub works.

    so i can't do this :

    switch (_runtimeState.Level)
    {
       case Umbraco.Cms.Core.RuntimeLevel.Run:
           endpoints.MapHub<SyncHub>(GetuSyncHubRoute());
           break;
    }
    

    https://github.com/KevinJump/uSync8/blob/de4aeb02a41335738c8a8c1af165ad50f350c157/uSync.BackOffice/Hubs/uSyncHubRoutes.cs#L28

    However that might not matter in this case - the signalR hub doesn't do anything so adding it when the site isn't setup might be ok (i will check that).

  • Kevin Jump 2348 posts 14896 karma points MVP 8x c-trib
    Apr 23, 2021 @ 13:56
    Kevin Jump
    0

    Actually, that last bit was me.

    swapping to getting the service via the applicationBuilder not the passed in service .

    e.g

    var hubRoutes = applicationBuilder.ApplicationServices.GetRequiredService<uSyncHubRoutes>();       
    

    means the runtime is set. (guess its an order of execution thing)

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies