Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is MvcApplication.RegisterRoutes defined as static?

I know this could be silly, but would like gurus to clarify it for me... Why is this method defined as static ..

public class MvcApplication : System.Web.HttpApplication
{
    /* Why this method is declared as static? */
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapRoute(
            "Default",                                              // Route name
            "{controller}/{action}/{id}",                           // URL with parameters
            new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
        );

    }

    protected void Application_Start()
    {
        RegisterRoutes(RouteTable.Routes);
    }
}
like image 607
asyncwait Avatar asked Dec 22 '22 08:12

asyncwait


1 Answers

its static because it has no need to be a method directly related to instances of the class, but rather a method that can be used in a static context.

In other words, it only affects the parameter "routes", it doesn't use any class fields or members, so it makes sense it be made static.

like image 160
Mark Avatar answered Feb 03 '23 05:02

Mark