Adding custom routes?

Mar 5, 2009 at 4:11 AM
I'm attempting to create a few custom routes in my Oxite app.

I've created a class that mimics the behavior of OxiteRoutes, it also extends IRegisterRoutes.  Then, I have it setup in my ContainerFactory to RegisterType for my new route class.

In the OxiteApplication, when registerRoutes is called, my new route class doesnt seem to get registered.

This code in registerRoutes leads me to believe it will register any class that implements IRegisterRoutes:


foreach (IRegisterRoutes routeRegistrar in getContainer().ResolveAll<IRegisterRoutes>()) 
{
    routeRegistrar.RegisterRoutes(
RouteTable.Routes); 
}



This code is not resolving the OxiteRoutes class nor my new routes class.

Am I going about this all wrong?  I would prefer not to have my applications routes in the OxiteRoutes class mainly so I don't have to merge them back in later when I get new code from SVN.

What is the best way to add my own routes to Oxite?

Thanks,

-Wick

 

Coordinator
Mar 5, 2009 at 4:14 AM
You're going down the right path for sure.  This one got me at first too.  When you register your IRegisterRoutes implementation be sure to give it a name when you add it to the container or it won't get picked up by ResolveAll.  The name can be anything.  HTH
Mar 6, 2009 at 12:16 AM
So now that I've named my IRegisterRoutes class, it is getting picked up by ResolveAll.

However, when I go to the routed URL I'm getting the oxite 404 page.  If I add it directy to OxideRoutes it works as expected.

I'm kinda stumped.
Coordinator
Mar 6, 2009 at 12:26 AM
It sounds like the base oxite routes aren't getting picked up anymore.

Do you still have a getContainer().Resolve<IRegisterRoutes>().RegisterRoutes(RouteTable.Routes); line before the loop on ResolveAll?  The default oxite routes don't have a name in the container so Resolve<> will return it, but ResolveAll won't so we can call ours first.  Ensure that's happening.
Coordinator
Mar 6, 2009 at 12:33 AM
I had to move the

getContainer().Resolve<

IRegisterRoutes>().RegisterRoutes(RouteTable.Routes);

 



line to *below* the for each loop.

I haven't checked this change in, but the result is to register your route first, which is important because we have a catch all route at the end of the base routes that is probably getting in the way of your new one.
Coordinator
Mar 6, 2009 at 12:37 AM
Ah, yup, good call.  Forgot they needed to be reversed.
Mar 6, 2009 at 3:22 AM
Sweet, that's it.  Thanks for the help.

Do I need to reverse them in the "registerActionFilters" method as well?
Coordinator
Mar 6, 2009 at 3:56 AM
You shouldn't need to, no.  In that case you want the base filters to run first.