haacked/routemagic

General questions - not an issue but seeking more info

Opened this issue · 4 comments

Does the EditableRoutes process presume to replace the Routes table. or does it augment? Do you run it before or after the main Routes are defined elsewhere?

I technically have the pkg 'working', in that it is executing (from Global.asax.cs) and updating the Routes based on ./Config/Routes.cs, but it's wiping out the Routes that have collected up to this point.

It seems that the Collection data is not being passed into the Routes.RegisterRoutes() method when the file is processed. What might I be missing, do you think?

Hi @seanyeomans, yep, it reloads the route. You can see that here: https://github.com/Haacked/RouteMagic/blob/master/src/RouteMagic/RouteRegistrationExtensions.cs#L27

The reason is that when you change the file, we don't diff the changes. We just take the easy way out and reload.

In theory, we could be smarter about this and not reload them, but just apply the changes. If that's something you'd want to take a crack at, I can help you with the pull request. 😄

Turns out we were able to circumvent this happening by running a call to our own routes inside the RegisterRoutes extension, instead of loading them from Global.asax,

The idea is to incorporate routes from a DB table, allowing the users to add new ones through a cms. fun stuff.

public void RegisterRoutes(RouteCollection routes)
{
   MvcApplication.RegisterRoutes(routes); // fire up tertiary routes

   //loop through DB retrieved routes
 .......
    routes.Add("", new LegacyRoute("mooo", "LegacyExternal", 
      new { externalUrl = "http://www.facebook.com/pages/<snip>" }));

  ......
   //endloop
}

edit:
I don't know why this post looks all weird....

Cool! And that sticks around if you then edit the routes in Config/Routes.cs?

p.s. The reason the formatting was off was you didn't indent the first line four spaces. I edited it to fix it by using the triple tick mark syntax instead. It's a better way to add code blocks to a comment. :)

yessir, it sticks.

In theory Config/Routes.cs will never be edited again, but rather the routes are populated on the fly from a db IService call.