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...
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 !:)
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:
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...
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.
https://docs.microsoft.com/en-us/aspnet/core/fundamentals/startup?view=aspnetcore-5.0#extend-startup-with-startup-filters
Does this help? In my package migration I've added an extension method that you can see here.
Which is called from
Startup.cs
:So not using a component, but seems like you may be able to do similar.
Andy
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 !:)
is working on a reply...