コード例 #1
0
        public ControllerMapper(ITypeFinder typeFinder, IDefinitionManager definitionManager)
        {
            IList <ControlsAttribute> controllerDefinitions = FindControllers(typeFinder);

            foreach (ItemDefinition id in definitionManager.GetDefinitions())
            {
                IAdapterDescriptor controllerDefinition = GetControllerFor(id, controllerDefinitions);
                if (controllerDefinition != null)
                {
                    ControllerMap[id.ItemType] = controllerDefinition.ControllerName;

                    // interacting with static context is tricky, here I made the assumtion that the last
                    // finder is the most relevat and takes the place of previous ones, this makes a few
                    // tests pass and doesn't seem to be called in production
                    foreach (var finder in PathDictionary.GetFinders(id.ItemType).Where(f => f is ActionResolver))
                    {
                        PathDictionary.RemoveFinder(id.ItemType, finder);
                    }

                    // Use MVC's ReflectedControllerDescriptor to find all actions on the Controller
                    var methods = new ReflectedControllerDescriptor(controllerDefinition.AdapterType)
                                  .GetCanonicalActions()
                                  .Select(m => m.ActionName).ToArray();
                    var actionResolver = new ActionResolver(this, methods);

                    _controllerActionMap[controllerDefinition.ControllerName] = methods;

                    PathDictionary.PrependFinder(id.ItemType, actionResolver);
                }
            }
        }
コード例 #2
0
 public int CompareTo(IAdapterDescriptor other)
 {
     return(Utility.InheritanceDepth(other.ItemType) - Utility.InheritanceDepth(ItemType));
 }