What calls RouteProvider.RegisterRoutes() Method

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
11 anos atrás
I see RouteProvider.cs class in each Plugin, etc. but I wonder what calls these methods and where? It is a partial class but since they have their own namespaces, they cannot be combined. What class registers all these providers to RouteTable?

public partial class RouteProvider : IRouteProvider
    {
        public void RegisterRoutes(RouteCollection routes)
        {
            routes.MapRoute("Plugin.Widgets.GoogleAnalytics.Configure",
                 "Plugins/WidgetsGoogleAnalytics/Configure",
                 new { controller = "WidgetsGoogleAnalytics", action = "Configure" },
                 new[] { "Nop.Plugin.Widgets.GoogleAnalytics.Controllers" }
            );

            //routes.MapRoute("Plugin.Widgets.GoogleAnalytics.PublicInfo",
            //     "Plugins/WidgetsGoogleAnalytics/PublicInfo",
            //     new { controller = "WidgetsGoogleAnalytics", action = "PublicInfo" },
            //     new[] { "Nop.Plugin.Widgets.GoogleAnalytics.Controllers" }
            //);
        }
        public int Priority
        {
            get
            {
                return 0;
            }
        }
    }
11 anos atrás
RoutePublisher in Nop.Web.Framework.Mvc.Routes
11 anos atrás
Thanks for the response but what calls RegisterRoutes() method in Nop.Web.Framework.Mvc.Routes.RoutePublisher. It seems something instantiate this class and pass a TypeFinder object which finds all the IRouteProvider. But I like to lean to see how this TypeFinder is implemented and what instantiates this RoutePublisher.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Routing;
using Nop.Core.Infrastructure;

namespace Nop.Web.Framework.Mvc.Routes
{
    public class RoutePublisher : IRoutePublisher
    {
        private readonly ITypeFinder _typeFinder;

        public RoutePublisher(ITypeFinder typeFinder)
        {
            this._typeFinder = typeFinder;
        }

        public void RegisterRoutes(RouteCollection routes)
        {
            var routeProviderTypes = _typeFinder.FindClassesOfType<IRouteProvider>();
            var routeProviders = new List<IRouteProvider>();
            foreach (var providerType in routeProviderTypes)
            {
                var provider = Activator.CreateInstance(providerType) as IRouteProvider;
                routeProviders.Add(provider);
            }
            routeProviders = routeProviders.OrderByDescending(rp => rp.Priority).ToList();
            routeProviders.ForEach(rp => rp.RegisterRoutes(routes));
        }
    }
}
11 anos atrás
In global.asax.cs IRoutePublisher is resolved to RoutePublisher (as defined in DependencyRegistrar)
and method RegisterRoutes is called.

RegisterRoutes uses ITypeFinder to load all assemblies and look for a specific type (IRouteProvider
in this case).

ITypeFinder is implemented by AppDomainTypeFinder and inherited by WebAppTypeFinder.
WebAppTypeFinder is setup to resolve ITypeFinder, this happens in ContainerConfigurer.

To Summarize: On startup RoutePublisher.RegisterRoutes is called, which in turn uses AppDomainTypeFinder  via WebAppTypeFinder to load all instances of IRouteProvider and call its RegisterRoutes method.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.