Skip to content

Commit 08c3931

Browse files
authored
Merge pull request #7039 from warrenbuckley/signalr-v13-update
Ammends SignalR docs to be simpier as the umbraco path can not be con…
2 parents f7a308c + 1e36e83 commit 08c3931

File tree

5 files changed

+31
-256
lines changed
  • 10/umbraco-cms/implementation/custom-routing
  • 13/umbraco-cms/implementation/custom-routing
  • 14/umbraco-cms/implementation/custom-routing
  • 15/umbraco-cms/implementation/custom-routing
  • 16/umbraco-cms/implementation/custom-routing

5 files changed

+31
-256
lines changed

10/umbraco-cms/implementation/custom-routing/signalR.md

+6-51
Original file line numberDiff line numberDiff line change
@@ -34,53 +34,9 @@ public class TestHub : Hub<ITestHubEvents>
3434
}
3535
```
3636

37-
## Define a custom route
38-
39-
Next up, is defining a custom route. For this, we are going to use a `IAreaRoutes` and the base umbrace backend path so we dont have to reserve another path in the settings.
40-
41-
```csharp
42-
using Microsoft.AspNetCore.Builder;
43-
using Microsoft.Extensions.DependencyInjection;
44-
using Umbraco.Cms.Core.Composing;
45-
using Umbraco.Cms.Core.DependencyInjection;
46-
using Umbraco.Cms.Web.Common.ApplicationBuilder;
47-
using Umbraco.Extensions;
48-
49-
public class TestHubRoutes : IAreaRoutes
50-
{
51-
private readonly IRuntimeState _runtimeState;
52-
private readonly string _umbracoPathSegment;
53-
54-
public TestHubRoutes(
55-
IOptions<GlobalSettings> globalSettings,
56-
IHostingEnvironment hostingEnvironment,
57-
IRuntimeState runtimeState)
58-
{
59-
_runtimeState = runtimeState;
60-
_umbracoPathSegment = globalSettings.Value.GetUmbracoMvcArea(hostingEnvironment);
61-
}
62-
63-
public void CreateRoutes(IEndpointRouteBuilder endpoints)
64-
{
65-
switch (_runtimeState.Level)
66-
{
67-
case Umbraco.Cms.Core.RuntimeLevel.Run:
68-
endpoints.MapHub<TestHub>(GetTestHubRoute());
69-
break;
70-
}
71-
72-
}
73-
74-
public string GetTestHubRoute()
75-
{
76-
return $"/{_umbracoPathSegment}/{nameof(TestHub)}";
77-
}
78-
}
79-
```
80-
8137
### Add the routing to the Umbraco Composer
8238

83-
Last step in the setup is registering our custom route:
39+
The next step in the setup is registering our custom route:
8440

8541
```csharp
8642
using Microsoft.AspNetCore.Builder;
@@ -101,18 +57,17 @@ public class TestHubComposer : IComposer
10157
builder.Services.AddSignalR();
10258
}
10359

104-
// next is adding the routes we defined earlier
105-
builder.Services.AddUnique<TestHubRoutes>();
10660
builder.Services.Configure<UmbracoPipelineOptions>(options =>
10761
{
10862
options.AddFilter(new UmbracoPipelineFilter(
109-
"test",
110-
endpoints: applicationBuilder =>
63+
"Signalr",
64+
endpoints: applicationBuilder =>
11165
{
11266
applicationBuilder.UseEndpoints(e =>
11367
{
114-
var hubRoutes = applicationBuilder.ApplicationServices.GetRequiredService<TestHubRoutes>();
115-
hubRoutes.CreateRoutes(e);
68+
e.MapHub<TestHub>($"/umbraco/{nameof(TestHub)}");
69+
70+
// Register more SignalR hubs or routes here...
11671
});
11772
}
11873
));

13/umbraco-cms/implementation/custom-routing/signalR.md

+6-51
Original file line numberDiff line numberDiff line change
@@ -34,53 +34,9 @@ public class TestHub : Hub<ITestHubEvents>
3434
}
3535
```
3636

37-
## Define a custom route
38-
39-
Next up, is defining a custom route. For this, we are going to use a `IAreaRoutes` and the base umbrace backend path so we dont have to reserve another path in the settings.
40-
41-
```csharp
42-
using Microsoft.AspNetCore.Builder;
43-
using Microsoft.Extensions.DependencyInjection;
44-
using Umbraco.Cms.Core.Composing;
45-
using Umbraco.Cms.Core.DependencyInjection;
46-
using Umbraco.Cms.Web.Common.ApplicationBuilder;
47-
using Umbraco.Extensions;
48-
49-
public class TestHubRoutes : IAreaRoutes
50-
{
51-
private readonly IRuntimeState _runtimeState;
52-
private readonly string _umbracoPathSegment;
53-
54-
public TestHubRoutes(
55-
IOptions<GlobalSettings> globalSettings,
56-
IHostingEnvironment hostingEnvironment,
57-
IRuntimeState runtimeState)
58-
{
59-
_runtimeState = runtimeState;
60-
_umbracoPathSegment = globalSettings.Value.GetUmbracoMvcArea(hostingEnvironment);
61-
}
62-
63-
public void CreateRoutes(IEndpointRouteBuilder endpoints)
64-
{
65-
switch (_runtimeState.Level)
66-
{
67-
case Umbraco.Cms.Core.RuntimeLevel.Run:
68-
endpoints.MapHub<TestHub>(GetTestHubRoute());
69-
break;
70-
}
71-
72-
}
73-
74-
public string GetTestHubRoute()
75-
{
76-
return $"/{_umbracoPathSegment}/{nameof(TestHub)}";
77-
}
78-
}
79-
```
80-
8137
### Add the routing to the Umbraco Composer
8238

83-
Last step in the setup is registering our custom route:
39+
The next step in the setup is registering our custom route:
8440

8541
```csharp
8642
using Microsoft.AspNetCore.Builder;
@@ -101,18 +57,17 @@ public class TestHubComposer : IComposer
10157
builder.Services.AddSignalR();
10258
}
10359

104-
// next is adding the routes we defined earlier
105-
builder.Services.AddUnique<TestHubRoutes>();
10660
builder.Services.Configure<UmbracoPipelineOptions>(options =>
10761
{
10862
options.AddFilter(new UmbracoPipelineFilter(
109-
"test",
110-
endpoints: applicationBuilder =>
63+
"Signalr",
64+
endpoints: applicationBuilder =>
11165
{
11266
applicationBuilder.UseEndpoints(e =>
11367
{
114-
var hubRoutes = applicationBuilder.ApplicationServices.GetRequiredService<TestHubRoutes>();
115-
hubRoutes.CreateRoutes(e);
68+
e.MapHub<TestHub>($"/umbraco/{nameof(TestHub)}");
69+
70+
// Register more SignalR hubs or routes here...
11671
});
11772
}
11873
));

14/umbraco-cms/implementation/custom-routing/signalR.md

+7-52
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
description: "Umbraco ships with signalR installed, find out how to add your own hub(s) to the existing setup"
2+
description: "Umbraco ships with SignalR installed, find out how to add your own hub(s) to the existing setup"
33
---
44

55
# Adding a hub with SignalR and Umbraco
@@ -34,53 +34,9 @@ public class TestHub : Hub<ITestHubEvents>
3434
}
3535
```
3636

37-
## Define a custom route
38-
39-
Next up, is defining a custom route. For this, we are going to use a `IAreaRoutes` and the base umbrace backend path so we dont have to reserve another path in the settings.
40-
41-
```csharp
42-
using Microsoft.AspNetCore.Builder;
43-
using Microsoft.Extensions.DependencyInjection;
44-
using Umbraco.Cms.Core.Composing;
45-
using Umbraco.Cms.Core.DependencyInjection;
46-
using Umbraco.Cms.Web.Common.ApplicationBuilder;
47-
using Umbraco.Extensions;
48-
49-
public class TestHubRoutes : IAreaRoutes
50-
{
51-
private readonly IRuntimeState _runtimeState;
52-
private readonly string _umbracoPathSegment;
53-
54-
public TestHubRoutes(
55-
IOptions<GlobalSettings> globalSettings,
56-
IHostingEnvironment hostingEnvironment,
57-
IRuntimeState runtimeState)
58-
{
59-
_runtimeState = runtimeState;
60-
_umbracoPathSegment = globalSettings.Value.GetUmbracoMvcArea(hostingEnvironment);
61-
}
62-
63-
public void CreateRoutes(IEndpointRouteBuilder endpoints)
64-
{
65-
switch (_runtimeState.Level)
66-
{
67-
case Umbraco.Cms.Core.RuntimeLevel.Run:
68-
endpoints.MapHub<TestHub>(GetTestHubRoute());
69-
break;
70-
}
71-
72-
}
73-
74-
public string GetTestHubRoute()
75-
{
76-
return $"/{_umbracoPathSegment}/{nameof(TestHub)}";
77-
}
78-
}
79-
```
80-
8137
### Add the routing to the Umbraco Composer
8238

83-
Last step in the setup is registering our custom route:
39+
The next step in the setup is registering our custom route:
8440

8541
```csharp
8642
using Microsoft.AspNetCore.Builder;
@@ -101,18 +57,17 @@ public class TestHubComposer : IComposer
10157
builder.Services.AddSignalR();
10258
}
10359

104-
// next is adding the routes we defined earlier
105-
builder.Services.AddUnique<TestHubRoutes>();
10660
builder.Services.Configure<UmbracoPipelineOptions>(options =>
10761
{
10862
options.AddFilter(new UmbracoPipelineFilter(
109-
"test",
110-
endpoints: applicationBuilder =>
63+
"Signalr",
64+
endpoints: applicationBuilder =>
11165
{
11266
applicationBuilder.UseEndpoints(e =>
11367
{
114-
var hubRoutes = applicationBuilder.ApplicationServices.GetRequiredService<TestHubRoutes>();
115-
hubRoutes.CreateRoutes(e);
68+
e.MapHub<TestHub>($"/umbraco/{nameof(TestHub)}");
69+
70+
// Register more SignalR hubs or routes here...
11671
});
11772
}
11873
));

15/umbraco-cms/implementation/custom-routing/signalR.md

+6-51
Original file line numberDiff line numberDiff line change
@@ -34,53 +34,9 @@ public class TestHub : Hub<ITestHubEvents>
3434
}
3535
```
3636

37-
## Define a custom route
38-
39-
Next up, is defining a custom route. Use `IAreaRoutes` and the base Umbraco backend path so there's no need to reserve another path in the settings.
40-
41-
```csharp
42-
using Microsoft.AspNetCore.Builder;
43-
using Microsoft.Extensions.DependencyInjection;
44-
using Umbraco.Cms.Core.Composing;
45-
using Umbraco.Cms.Core.DependencyInjection;
46-
using Umbraco.Cms.Web.Common.ApplicationBuilder;
47-
using Umbraco.Extensions;
48-
49-
public class TestHubRoutes : IAreaRoutes
50-
{
51-
private readonly IRuntimeState _runtimeState;
52-
private readonly string _umbracoPathSegment;
53-
54-
public TestHubRoutes(
55-
IOptions<GlobalSettings> globalSettings,
56-
IHostingEnvironment hostingEnvironment,
57-
IRuntimeState runtimeState)
58-
{
59-
_runtimeState = runtimeState;
60-
_umbracoPathSegment = globalSettings.Value.GetUmbracoMvcArea(hostingEnvironment);
61-
}
62-
63-
public void CreateRoutes(IEndpointRouteBuilder endpoints)
64-
{
65-
switch (_runtimeState.Level)
66-
{
67-
case Umbraco.Cms.Core.RuntimeLevel.Run:
68-
endpoints.MapHub<TestHub>(GetTestHubRoute());
69-
break;
70-
}
71-
72-
}
73-
74-
public string GetTestHubRoute()
75-
{
76-
return $"/{_umbracoPathSegment}/{nameof(TestHub)}";
77-
}
78-
}
79-
```
80-
8137
### Add the routing to the Umbraco Composer
8238

83-
Last step in the setup is registering our custom route:
39+
The next step in the setup is registering our custom route:
8440

8541
```csharp
8642
using Microsoft.AspNetCore.Builder;
@@ -101,18 +57,17 @@ public class TestHubComposer : IComposer
10157
builder.Services.AddSignalR();
10258
}
10359

104-
// next is adding the routes we defined earlier
105-
builder.Services.AddUnique<TestHubRoutes>();
10660
builder.Services.Configure<UmbracoPipelineOptions>(options =>
10761
{
10862
options.AddFilter(new UmbracoPipelineFilter(
109-
"test",
110-
endpoints: applicationBuilder =>
63+
"Signalr",
64+
endpoints: applicationBuilder =>
11165
{
11266
applicationBuilder.UseEndpoints(e =>
11367
{
114-
var hubRoutes = applicationBuilder.ApplicationServices.GetRequiredService<TestHubRoutes>();
115-
hubRoutes.CreateRoutes(e);
68+
e.MapHub<TestHub>($"/umbraco/{nameof(TestHub)}");
69+
70+
// Register more SignalR hubs or routes here...
11671
});
11772
}
11873
));

0 commit comments

Comments
 (0)