ASP.NET launches new version for ASP.NET MVC. That is ASP.NET MVC 5.2. The Model-View-Controller (MVC) pattern is an architectural design principle that separates the components of a Web application. This separation gives you more control over the individual parts of the application, which lets you more easily develop, modify, and test them.
What’s new in ASP.NET MVC 5.2? Well, they offer new feature from Attribute Routing. Attribute Routing now provides an extensibility point called IDirectRouteProvider, which allows full control over how attribute routes are discovered and configured.
The good news for developer ASP.NET MVC 5.2 is the new IDirectRouteProvider is responsible for providing a list of actions and controllers along with associated route information to specify exactly what routing configuration is desired for those actions. An IDirectRouteProvider implementation may be specified when calling MapAttributes/MapHttpAttributeRoutes.
There is syntax for MapAttributes/MapHttpAttributeRoutes
public static void MapHttpAttributeRoutes(
this HttpConfiguration configuration
)
Extending the default implementation with DefaultDirectRouteProvider will be easier for customizing IDirectRouteProvider. Because this class provides separate overridable virtual methods to change the logic for discovering attributes, creating route entries, and discovering route prefix and area prefix.
IDirectRouteProvider.cs
using System.Collections.Generic;
#if ASPNETWEBAPI
using System.Web.Http.Controllers;
#endif
#if ASPNETWEBAPI
namespace System.Web.Http.Routing
#else
namespace System.Web.Mvc.Routing
#endif
{
/// <summary>
/// Defines a provider for routes that directly target action descriptors (attribute routes).
/// </summary>
public interface IDirectRouteProvider
{
/// <summary>Gets the direct routes for a controller.</summary>
/// <param name="controllerDescriptor">The controller descriptor.</param>
/// <param name="actionDescriptors">The action descriptors.</param>
/// <param name="constraintResolver">The inline constraint resolver.</param>
/// <returns>A set of route entries for the controller.</returns>
#if ASPNETWEBAPI
IReadOnlyList<RouteEntry> GetDirectRoutes(
HttpControllerDescriptor controllerDescriptor,
IReadOnlyList<HttpActionDescriptor> actionDescriptors,
IInlineConstraintResolver constraintResolver);
#else
IReadOnlyList<RouteEntry> GetDirectRoutes(
ControllerDescriptor controllerDescriptor,
IReadOnlyList<ActionDescriptor> actionDescriptors,
IInlineConstraintResolver constraintResolver);
#endif
}
}