I have an MVC application with some basic routes and routes can be registered dynamiccly (although), that's the id.
I just have basic MVC implementation for the routes:
public class RouteConfig
{
#region Methods
/// <summary>
/// Registers the routes.
/// </summary>
/// <param name="routes">The <see cref="RouteCollection" /> to which the routes will be added.</param>
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional });
}
#endregion
}
Now, I would like something so that it's easy to add routes to the application, but you cannot toutch the source code above for registering routes.
I was thinking about an interface somewhere and that the RouteConfig class will search all the assemblies for classes that implements this interface and than execute the logic defined in there to register the routes, but I do have the feeling that this isn't the correct approach.
I tought about something like this:
Create an interface that defines the way to register routes:
public interface IMvcRouteExtender
{
#region Methods
/// <summary>
/// Register routes for the application.
/// </summary>
/// <param name="routes">The <see cref="RouteCollection"/> that contains all the required routes.</param>
void RegisterRoutes(RouteCollection routes);
#endregion
}
Create a class that implements this interface to register the required routes
public class RouteConfig : IMvcRouteExtender
{
#region IMvcRouteExtender
/// <summary>
/// Registers the routes.
/// </summary>
/// <param name="routes">The <see cref="RouteCollection" /> to which the routes will be added.</param>
public void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute("Default", "pensions/save-and-pension", new { controller = "Home", action = "Index", id = UrlParameter.Optional });
}
#endregion
}
But now the issue, how can I make sure that first the IgnoreRoute registration is done, and then calling this class and then registers the rest of the routes?
This all without having strong references between the 2 route configurations?
Has anyone faced something like this and is willing to help me?
I want to avoid tight coupling the RouteConfig to another assembly.
As the SOLID principles say, the system must be open for extension, but closed for modification.
Any help is highly appreciated.