public void RegisterRoutes() { // Get all Controllers var controllerObjs = _container.GetAllInstances(typeof(ChromelyController)).ToList(); if (controllerObjs != null && controllerObjs.Any()) { foreach (var obj in controllerObjs) { var controller = obj as ChromelyController; if (controller != null) { ServiceRouteProvider.RegisterActionRoutes(_container, controller.ActionRouteDictionary); ServiceRouteProvider.RegisterCommnandRoutes(_container, controller.CommandRouteDictionary); var actionRouteDictionary = new Dictionary <string, ActionRoute>(); var commandRouteDictionary = new Dictionary <string, CommandRoute>(); var controllerFactory = new ChromelyControllerFactory(_container); // Add Http Attributes var httpAttributeRoutes = controllerFactory.GetHttpAttributeRoutes(controller); if ((httpAttributeRoutes != null) && httpAttributeRoutes.Any()) { foreach (var item in httpAttributeRoutes) { if (!actionRouteDictionary.ContainsKey(item.Key)) { actionRouteDictionary.Add(item.Key, item.Value); } } } // Add Custom Attributes var customAttributeRoutes = controllerFactory.GetCommandAttributeRoutes(controller); if ((customAttributeRoutes != null) && customAttributeRoutes.Any()) { foreach (var item in customAttributeRoutes) { if (!commandRouteDictionary.ContainsKey(item.Key)) { commandRouteDictionary.Add(item.Key, item.Value); } } } ServiceRouteProvider.RegisterActionRoutes(_container, actionRouteDictionary); ServiceRouteProvider.RegisterCommnandRoutes(_container, commandRouteDictionary); } } } }
public virtual void RegisterAllRoutes(List <ChromelyController> controllers) { if (controllers == null || !controllers.Any()) { return; } try { var routeDictionary = new Dictionary <string, RequestActionRoute>(); var commandDictionary = new Dictionary <string, CommandActionRoute>(); foreach (var controller in controllers) { var controllerFactory = new ChromelyControllerFactory(); var currentRouteDictionary = controller.ActionRouteDictionary; var currentCommandDictionary = controller.CommandRouteDictionary; // Merge with return route dictionary if ((currentRouteDictionary != null) && currentRouteDictionary.Any()) { foreach (var item in currentRouteDictionary) { if (!routeDictionary.ContainsKey(item.Key)) { routeDictionary.Add(item.Key, item.Value); } } } // Merge with return command dictionary if ((currentCommandDictionary != null) && currentCommandDictionary.Any()) { foreach (var item in currentCommandDictionary) { if (!commandDictionary.ContainsKey(item.Key)) { commandDictionary.Add(item.Key, item.Value); } } } // Add Http Attributes var httpAttributeRoutes = controllerFactory.GetActionAttributeRoutes(controller); if ((httpAttributeRoutes != null) && httpAttributeRoutes.Any()) { foreach (var item in httpAttributeRoutes) { if (!routeDictionary.ContainsKey(item.Key)) { routeDictionary.Add(item.Key, item.Value); } } } // Add Custom Attributes var customAttributeRoutes = controllerFactory.GetCommandAttributeRoutes(controller); if ((customAttributeRoutes != null) && customAttributeRoutes.Any()) { foreach (var item in customAttributeRoutes) { if (!commandDictionary.ContainsKey(item.Key)) { commandDictionary.Add(item.Key, item.Value); } } } } RegisterActionRoutes(routeDictionary); RegisterCommandRoutes(commandDictionary); } catch (Exception exception) { Logger.Instance.Log.LogError(exception, "RouteScanner:Scan"); } }