Skip to content

Commit 35cdd74

Browse files
committed
Introduced MapDefaultAreaControllerRoute() extension method
The `MapDefaultAreaControllerRoute()` is analogous to the out-of-the-box `MapDefaultControllerRoute()` extension that ships with ASP.NET Core—except that it _also_ supports routes. This isn't _specific_ to OnTopic, but it's useful, in particular, for supporting explicit `{area}/{controller}/{action}/{id?}` style routes. This automatically registers _all_ areas to support this route.
1 parent 6c6ad74 commit 35cdd74

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

OnTopic.AspNetCore.Mvc/ServiceCollectionExtensions.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,22 @@ public static ControllerActionEndpointConventionBuilder MapTopicAreaRoute(
127127
defaults: new { controller = controller?? areaName, action, rootTopic = areaName }
128128
);
129129

130+
/*==========================================================================================================================
131+
| EXTENSION: MAP DEFAULT AREA CONTROLLER ROUTES (IENDPOINTROUTEBUILDER)
132+
\-------------------------------------------------------------------------------------------------------------------------*/
133+
/// <summary>
134+
/// Adds the fully-qualified <c>{area:exists}/{controller}/{action=Index}/{id?}</c> endpoint route for all areas.
135+
/// </summary>
136+
/// <remarks>
137+
/// This is analogous to the standard <see cref="ControllerEndpointRouteBuilderExtensions.MapDefaultControllerRoute(
138+
/// IEndpointRouteBuilder)"/> method that ships with ASP.NET, except that it works with areas.
139+
/// </remarks>
140+
public static void MapDefaultAreaControllerRoute(this IEndpointRouteBuilder routes) =>
141+
routes.MapControllerRoute(
142+
name: "TopicAreas",
143+
pattern: "{area:exists}/{controller}/{action=Index}/{id?}"
144+
);
145+
130146
/*==========================================================================================================================
131147
| EXTENSION: MAP TOPIC REDIRECT (IENDPOINTROUTEBUILDER)
132148
\-------------------------------------------------------------------------------------------------------------------------*/

0 commit comments

Comments
 (0)