public static class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.MapRoute...
}
}
public class RoutingComponent : IComponent
{
public void Initialize()
{
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
public void Terminate()
{
}
}
public class PackageComposer : IUserComposer
{
public void Compose(Composition composition)
{
composition.Components().Append<RoutingComponent>();
}
}
(Obviously the first and second class could be combined quite easily, but I had a particular reason for breaking it out).
Thanks for that Andy, however I can't seem to get this to work for creating custom MVC routes... it works great when trying to create new ScriptBundles though, so feel like I'm getting somewhere, thank you!
Would this be causing problems because BundleConfig.RegisterBundles was being called in OnApplicationStarting while RouteTable.Routes.MapRoute was called in OnApplicationStarted?
You should not have to register Controllers. They are always created via a factory that find them based on the route. The factory may also, as in the case in umbraco 8, be able to resolve dependencies.
This is definetly a codesmell you should look into.
Custom Routes and ScriptBundles
Previously in v7 we had some custom events handlers configured which implemented IApplicationEventHandler.
Then within OnApplicationStarting we'd fire off:
And then in OnApplicationStarted we'd have a few:
However it looks like ApplicationEventHandler is no longer in Umbraco.Core - could anyone give me some guidance on what to do here?
Thank you
You'll have to look into Composing:
https://our.umbraco.com/documentation/Implementation/Composing/
I've set this up with the following:
(Obviously the first and second class could be combined quite easily, but I had a particular reason for breaking it out).
Namespaces you'll need are:
Andy
Thanks for that Andy, however I can't seem to get this to work for creating custom MVC routes... it works great when trying to create new ScriptBundles though, so feel like I'm getting somewhere, thank you!
Would this be causing problems because BundleConfig.RegisterBundles was being called in OnApplicationStarting while RouteTable.Routes.MapRoute was called in OnApplicationStarted?
Thanks again, Warren
Not sure I'm afraid. All I would add is that I found I had to register any custom controllers with the IoC container.
I.e. in
PackageComposer.Compose()
(above) I've also got:Andy
You should not have to register Controllers. They are always created via a factory that find them based on the route. The factory may also, as in the case in umbraco 8, be able to resolve dependencies.
This is definetly a codesmell you should look into.
is working on a reply...