I am reading the documentation for SignalR for v13 and my question is do we need to do the part for defining a custom route using the approach of IAreaRoutes
?
I thought in more recent versions of Umbraco the value to the Umbraco backoffice part could no longer be changed, if I have remembered correctly this seems extra bloat to the code and documentation if it could be simplified.
Docs
Section I am not sure we need?
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Web.Common.ApplicationBuilder;
using Umbraco.Extensions;
public class TestHubRoutes : IAreaRoutes
{
private readonly IRuntimeState _runtimeState;
private readonly string _umbracoPathSegment;
public TestHubRoutes(
IOptions<GlobalSettings> globalSettings,
IHostingEnvironment hostingEnvironment,
IRuntimeState runtimeState)
{
_runtimeState = runtimeState;
_umbracoPathSegment = globalSettings.Value.GetUmbracoMvcArea(hostingEnvironment);
}
public void CreateRoutes(IEndpointRouteBuilder endpoints)
{
switch (_runtimeState.Level)
{
case Umbraco.Cms.Core.RuntimeLevel.Run:
endpoints.MapHub<TestHub>(GetTestHubRoute());
break;
}
}
public string GetTestHubRoute()
{
return $"/{_umbracoPathSegment}/{nameof(TestHub)}";
}
}
Could it be simplified like so?
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.DependencyInjection;
using Umbraco.Cms.Web.Common.ApplicationBuilder;
using Umbraco.Extensions;
public class TestHubComposer : IComposer
{
public void Compose(IUmbracoBuilder builder)
{
// first we are going to add signalR to the serviceCollection if no hubs have been added yet
// this is just in case Umbraco ever decides to use a different technology
if (!builder.Services.Any(x => x.ServiceType == typeof(IHubContext<>)))
{
builder.Services.AddSignalR();
}
// next is adding the routes we defined earlier
builder.Services.AddUnique<TestHubRoutes>();
builder.Services.Configure<UmbracoPipelineOptions>(options =>
{
options.AddFilter(new UmbracoPipelineFilter(
"test",
endpoints: applicationBuilder =>
{
applicationBuilder.UseEndpoints(e =>
{
// NEW: We know the path of umbraco can not be changed
// and using IAreaRoutes to calculate the path seems overkill ?
e.MapHub<TestHub>($"/umbraco/{nameof(TestHub)}";
// Previous code
// var hubRoutes = applicationBuilder.ApplicationServices.GetRequiredService<TestHubRoutes>();
// hubRoutes.CreateRoutes(e);
});
}
));
});
}
}
Clarification
So can anyone confirm that perhaps this is no longer needed and in fact we can not configure the path of Umbraco anymore?