Skip to content

Commit 6c6ad74

Browse files
committed
Introduced MapTopicAreaRoute() extension method.
This is identical to the existing `MapTopicRoute()` extension method, but it accounts for routes. It accepts an `areaName`, and will default to a `controller` of the same name if not otherwise provided. (In this way, `areaName` is analogous to `rootTopic`—and, indeed, will be set to `rootTopic` in the `defaults`.) An `action` can also be supplied, otherwise it will default to `Index`.
1 parent 30c6691 commit 6c6ad74

1 file changed

Lines changed: 25 additions & 0 deletions

File tree

OnTopic.AspNetCore.Mvc/ServiceCollectionExtensions.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,31 @@ public static ControllerActionEndpointConventionBuilder MapTopicRoute(
102102
defaults: new { controller, action, rootTopic }
103103
);
104104

105+
/*==========================================================================================================================
106+
| EXTENSION: MAP TOPIC AREA ROUTE (IENDPOINTROUTEBUILDER)
107+
\-------------------------------------------------------------------------------------------------------------------------*/
108+
/// <summary>
109+
/// Adds the <c>{areaName}/{**path}</c> endpoint route for a specific area, which enables the areas to be mapped to
110+
/// specific topics via the <see cref="TopicRepositoryExtensions.Load(Repositories.ITopicRepository, RouteData)"/>
111+
/// extension method used by <see cref="TopicController"/>.
112+
/// </summary>
113+
/// <remarks>
114+
/// If there are multiple routes that fit this description, you can instead opt to use the <see cref=
115+
/// "MapTopicAreaRoute(IEndpointRouteBuilder)"/> extension, which will register all areas.
116+
/// </remarks>
117+
public static ControllerActionEndpointConventionBuilder MapTopicAreaRoute(
118+
this IEndpointRouteBuilder routes,
119+
string areaName,
120+
string? controller = null,
121+
string action = "Index"
122+
) =>
123+
routes.MapAreaControllerRoute(
124+
name: $"TopicAreas",
125+
areaName: areaName,
126+
pattern: areaName + "/{**path}",
127+
defaults: new { controller = controller?? areaName, action, rootTopic = areaName }
128+
);
129+
105130
/*==========================================================================================================================
106131
| EXTENSION: MAP TOPIC REDIRECT (IENDPOINTROUTEBUILDER)
107132
\-------------------------------------------------------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)