|
3 | 3 | | Client Ignia, LLC
|
4 | 4 | | Project Topics Library
|
5 | 5 | \=============================================================================================================================*/
|
6 |
| -using OnTopic.AspNetCore.Mvc.Controllers; |
7 |
| -using OnTopic.Internal.Diagnostics; |
| 6 | +using System; |
8 | 7 | using Microsoft.AspNetCore.Builder;
|
9 | 8 | using Microsoft.AspNetCore.Mvc.Infrastructure;
|
| 9 | +using Microsoft.AspNetCore.Mvc.TagHelpers; |
10 | 10 | using Microsoft.AspNetCore.Routing;
|
11 | 11 | using Microsoft.Extensions.DependencyInjection;
|
12 | 12 | using Microsoft.Extensions.DependencyInjection.Extensions;
|
| 13 | +using OnTopic.AspNetCore.Mvc.Controllers; |
| 14 | +using OnTopic.Internal.Diagnostics; |
13 | 15 |
|
14 | 16 | namespace OnTopic.AspNetCore.Mvc {
|
15 | 17 |
|
@@ -38,6 +40,7 @@ public static IMvcBuilder AddTopicSupport(this IMvcBuilder services) {
|
38 | 40 | | Register services
|
39 | 41 | \-----------------------------------------------------------------------------------------------------------------------*/
|
40 | 42 | services.Services.TryAddSingleton<IActionResultExecutor<TopicViewResult>, TopicViewResultExecutor>();
|
| 43 | + services.Services.TryAddSingleton<TopicRouteValueTransformer>(); |
41 | 44 |
|
42 | 45 | /*------------------------------------------------------------------------------------------------------------------------
|
43 | 46 | | Configure services
|
@@ -127,6 +130,21 @@ public static ControllerActionEndpointConventionBuilder MapTopicAreaRoute(
|
127 | 130 | defaults: new { controller = controller?? areaName, action, rootTopic = areaName }
|
128 | 131 | );
|
129 | 132 |
|
| 133 | + /// <summary> |
| 134 | + /// Adds the <c>{area:exists}/{**path}</c> endpoint route for all areas, which enables the areas to be mapped to specific |
| 135 | + /// topics via the <see cref="TopicRepositoryExtensions.Load(Repositories.ITopicRepository, RouteData)"/> extension method |
| 136 | + /// used by <see cref="TopicController"/>. |
| 137 | + /// </summary> |
| 138 | + /// <remarks> |
| 139 | + /// Be aware that this method uses the <see cref="ControllerEndpointRouteBuilderExtensions.MapDynamicControllerRoute{ |
| 140 | + /// TTransformer}(IEndpointRouteBuilder, String)"/> method. In .NET 3.x, this is incompatible with both the <see cref= |
| 141 | + /// "AnchorTagHelper"/> and <see cref="LinkGenerator"/> classes. This means that e.g. <c>@Url.Action()</c> references |
| 142 | + /// in views won't be properly formed. If these are required, prefer registering each route individually using <see cref= |
| 143 | + /// "MapTopicAreaRoute(IEndpointRouteBuilder, String, String?, String)"/>. |
| 144 | + /// </remarks> |
| 145 | + public static void MapTopicAreaRoute(this IEndpointRouteBuilder routes) => |
| 146 | + routes.MapDynamicControllerRoute<TopicRouteValueTransformer>("{area:exists}/{**path}"); |
| 147 | + |
130 | 148 | /*==========================================================================================================================
|
131 | 149 | | EXTENSION: MAP DEFAULT AREA CONTROLLER ROUTES (IENDPOINTROUTEBUILDER)
|
132 | 150 | \-------------------------------------------------------------------------------------------------------------------------*/
|
|
0 commit comments