Extending the MVC Routecollection I'm currently developping an MVC framework on which I will be writing my websites. This is done through the usage of a starter kit.

In standard MVC, your routes are registered like the following:


/// &lt;summary&gt;
///     Registers the routes.
/// &lt;/summary&gt;
/// &lt;param name="routes"&gt;The &lt;see cref="RouteCollection" /&gt; to which the routes will be added.&lt;/param&gt;
public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    // All the required routes are placed here.
    routes.MapRoute("Website", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional });
}



But since it's a framework, there's a need to add routes to the collection, so I started with an interface:

public interface IMvcRouteExtender
{
    #region Methods

    /// &lt;summary&gt;
    ///     Register routes for the application.
    /// &lt;/summary&gt;
    /// &lt;param name="routes"&gt;The &lt;see cref="RouteCollection"/&gt; that contains all the required routes.&lt;/param&gt;
    void RegisterRoutes(RouteCollection routes);

    #endregion
}


Now, in an implementation class, I can do the following:

public class CustomRouteConfiguration : IMvcRouteExtender
{
    #region IMvcRouteExtender

    /// &lt;summary&gt;
    ///     Registers the routes.
    /// &lt;/summary&gt;
    /// &lt;param name="routes"&gt;The &lt;see cref="RouteCollection" /&gt; to which the routes will be added.&lt;/param&gt;
    public void RegisterRoutes(RouteCollection routes)
    {
        routes.MapRoute("Default", "pensions/save-and-pension", new { controller = "Home", action = "Index", id = UrlParameter.Optional });
    }

    #endregion
}


In order to be sure there available, the original routeconfig is changed so that it searches for those interfaces and register them.

/// &lt;summary&gt;
///     Registers the routes.
/// &lt;/summary&gt;
/// &lt;param name="routes"&gt;The &lt;see cref="RouteCollection" /&gt; to which the routes will be added.&lt;/param&gt;
public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    // Get all the types in the references assembly that implement the 'IMvcRouteExtender' interface.
    var types = AppDomain.CurrentDomain.GetAssemblies().ToList()
                .SelectMany(a =&gt; a.GetTypes())
                .Where(t =&gt; typeof(IMvcRouteExtender).IsAssignableFrom(t) &amp;&amp; !t.IsInterface);

    // Register all the routes.
    types.Select(type =&gt; Activator.CreateInstance(type) as IMvcRouteExtender).Each(x =&gt; x.RegisterRoutes(routes));

    // All the required routes are placed here.
    routes.MapRoute("Website", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional });
}


As you'll see above, I'm using reflection to load the types in which the routes are defined. This is working fine, but I don't like the overhead of using reflection.

Is there anyone who has an idea on how to make this more efficient? AKA, remove the dynamic type loading?

Since I'm writing a framework I cannot have a reference between routeConfig and CustomRouteConfig.

Also: Don't look at code semantics here, I'm just talking about a general idea to make the code more performant.
It was more or less worked out in the comments that the use of reflection is a fine way to go about it and I agree with that. What I can't understand is your use of regions. In IMvcRouteExtender you have one that wraps a single method. In my opinion, it just clutters the code. In your implementation, you have a #region IMvcRouteExtender. This is a little stickier. I could definitely see a benefit to this if your class was implementing multiple interfaces and you had a region for each interface, but I would remove it for the code here. Clutter like this distracts us from the code. 

Some of your instructions also get kind of long. I'd shorten then up a bit with a few line breaks. 

/// &lt;summary&gt;
///     Registers the routes.
/// &lt;/summary&gt;
/// &lt;param name="routes"&gt;The &lt;see cref="RouteCollection" /&gt; to which the routes will be added.&lt;/param&gt;
public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    // Get all the types in the references assembly that implement the 'IMvcRouteExtender' interface.
    var types = AppDomain.CurrentDomain.GetAssemblies()
                .ToList()
                .SelectMany(a =&gt; a.GetTypes())
                .Where(t =&gt; typeof(IMvcRouteExtender).IsAssignableFrom(t) &amp;&amp; !t.IsInterface);

    // Register all the routes.
    types.Select(type =&gt; Activator.CreateInstance(type) as IMvcRouteExtender)
                .Each(x =&gt; x.RegisterRoutes(routes));

    // All the required routes are placed here.
    routes.MapRoute(
            "Website", 
            "{controller}/{action}/{id}", 
            new 
            {
            controller = "Home", 
            action = "Index",
            id = UrlParameter.Optional 
            });
}


It's certainly not ideal still, but I prefer vertical scroll to horizontal scroll. It lets us see what the method is doing "all at once".