Copied to clipboard

Flag this post as spam?

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

  • Nathan Woulfe 447 posts 1664 karma points MVP 5x hq c-trib
    May 20, 2021 @ 08:21
    Nathan Woulfe

    Adding custom surface routes - how to?

    I'm trying to define a controller route in a component, but running into issues with services not being available:

    public class RoutingComponent : IComponent
            private readonly IEndpointRouteBuilder _endpointBuilder;
            public RoutingComponent(IEndpointRouteBuilder endpointBuilder)
                _endpointBuilder = endpointBuilder;
            public void Initialize()
                // throws
            public void Terminate()

    Stack is this:

    InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Routing.IEndpointRouteBuilder' while attempting to activate 'Plumber.Web.Components.RoutingComponent'.

    How should I be approaching this? I need to define a particular route to manage with a content finder...

  • Mathias Hove 11 posts 74 karma points
    May 20, 2021 @ 11:27
    Mathias Hove

    Wouldn't utilizing a startup filter give you access to the IEndpointRouteBuilder ?

    Create a startupfilter, register it in a composer and access the UseEndpoints() method in IApplicationBuilder.

  • Andy Butland 422 posts 2334 karma points MVP 4x hq c-trib
    May 20, 2021 @ 13:10
    Andy Butland

    Does this help? In my package migration I've added an extension method that you can see here.

    Which is called from Startup.cs:

        public void ConfigureServices(IServiceCollection services) =>
            services.AddUmbraco(_env, _config)
        public void Configure(IApplicationBuilder app)
                .WithMiddleware(u =>
                .WithEndpoints(u =>

    So not using a component, but seems like you may be able to do similar.


  • Mathias Hove 11 posts 74 karma points
    May 20, 2021 @ 13:53
    Mathias Hove

    Andy, we are achieving the same, except that a startupfilter is separate from the startup class, and called under startup :) Benefit is that you don't need to call it manually trough an extension method. Its a better experience, when no setup from the user is required.

    Though I'm not 100% sure how routing interacts up against Umbraco, so it's something that needs testing !:)

Please Sign in or register to post replies

Write your reply to: