Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

RoutePublisher.cs

using Microsoft.AspNetCore.Routing;
using Nop.Core.Infrastructure;

namespace Nop.Web.Framework.Mvc.Routing;

/// 
/// Represents implementation of route publisher
/// 
public partial class RoutePublisher : IRoutePublisher
{
    #region Fields

    /// 
    /// Type finder
    /// 
    protected readonly ITypeFinder _typeFinder;

    #endregion

    #region Ctor

    /// 
    /// Ctor
    /// 
    /// Type finder
    public RoutePublisher(ITypeFinder typeFinder)
    {
        _typeFinder = typeFinder;
    }

    #endregion

    #region Methods

    /// 
    /// Register routes
    /// 
    /// Route builder
    public virtual void RegisterRoutes(IEndpointRouteBuilder endpointRouteBuilder)
    {
        //find route providers provided by other assemblies
        var routeProviders = _typeFinder.FindClassesOfType();

        //create and sort instances of route providers
        var instances = routeProviders
            .Select(routeProvider => (IRouteProvider)Activator.CreateInstance(routeProvider))
            .OrderByDescending(routeProvider => routeProvider.Priority);

        //register all provided routes
        foreach (var routeProvider in instances)
            routeProvider.RegisterRoutes(endpointRouteBuilder);
    }

    #endregion
}