Ejemplo n.º 1
0
        public Type GetRouteMapperType(RouteData routeData)
        {
            string area           = routeData.GetAreaName();
            string controllerName = routeData.GetControllerName();
            var    serviceKey     = ApiControllerConventional.GetControllerSerivceName(area, controllerName) + "Controller";

            return(_serviceCollection.GetLastNamedServiceType(serviceKey));
        }
Ejemplo n.º 2
0
        public void OnProvidersExecuting(ApplicationModelProviderContext context)
        {
            var allApiServices = _mvcControllerManager.GetAll();

            foreach (var controllerModel in context.Result.Controllers)
            {
                var apiService     = allApiServices.FirstOrDefault(s => s.ServiceInterfaceType == controllerModel.ControllerType);
                var controllerType = controllerModel.ControllerType;
                if (apiService != null)
                {
                    controllerModel.ControllerName = controllerType.Name.EndsWith(ApiControllerConventional.Postfixes().FirstOrDefault()) ?
                                                     controllerType.Name.Substring(0, controllerType.Name.Length - ApiControllerConventional.Postfixes().FirstOrDefault().Length) : controllerType.Name;
                    if (controllerModel.RouteValues.ContainsKey("area"))
                    {
                        controllerModel.RouteValues["area"] = apiService.ServicePrefix;
                    }
                    else
                    {
                        controllerModel.RouteValues.Add("area", apiService.ServicePrefix);
                    }
                }
            }
        }