0

ASP.NET MVC 中的 ResourceControllerFactory 和 DefaultControllerFactory 有什么区别?

上下文:我希望将 IOC 容器挂接到控制器工厂 - 我之前已经覆盖了DefaultControllerFactory执行此操作,但我看到在ResourceControllerFactory我目前正在使用的项目中使用它。

是否提供对 REST API 的改进支持?

每个代码:

默认控制器工厂

public class DefaultControllerFactory : IControllerFactory
{
    // Fields
    private IBuildManager _buildManager;
    private ControllerBuilder _controllerBuilder;
    private ControllerTypeCache _instanceControllerTypeCache;
    private static ControllerTypeCache _staticControllerTypeCache;

    // Methods
    static DefaultControllerFactory();
    public DefaultControllerFactory();
    internal static InvalidOperationException CreateAmbiguousControllerException(RouteBase route, string controllerName, ICollection<Type> matchingTypes);
    public virtual IController CreateController(RequestContext requestContext, string controllerName);
    protected internal virtual IController GetControllerInstance(RequestContext requestContext, Type controllerType);
    protected internal virtual Type GetControllerType(RequestContext requestContext, string controllerName);
    private Type GetControllerTypeWithinNamespaces(RouteBase route, string controllerName, HashSet<string> namespaces);
    public virtual void ReleaseController(IController controller);

    // Properties
    internal IBuildManager BuildManager { get; set; }
    internal ControllerBuilder ControllerBuilder { get; set; }
    internal ControllerTypeCache ControllerTypeCache { get; set; }
}

资源控制器工厂

public class ResourceControllerFactory : IControllerFactory
{
    // Fields
    private IControllerFactory inner;
    private const string restActionToken = "$REST$";

    // Methods
    public ResourceControllerFactory();
    public ResourceControllerFactory(IControllerFactory inner);
    public IController CreateController(RequestContext requestContext, string controllerName);
    public void ReleaseController(IController controller);

    // Nested Types
    private class ResourceControllerActionInvoker : ControllerActionInvoker
    {
        // Methods
        public ResourceControllerActionInvoker();
        protected override ActionDescriptor FindAction(ControllerContext controllerContext, ControllerDescriptor controllerDescriptor, string actionName);

        // Nested Types
        private class ResourceErrorActionDescriptor : ActionDescriptor
        {
            // Fields
            private ControllerDescriptor controllerDescriptor;
            private string message;
            private HttpStatusCode statusCode;

            // Methods
            public ResourceErrorActionDescriptor(ControllerDescriptor controllerDescriptor, HttpStatusCode statusCode, string message);
            public override object Execute(ControllerContext controllerContext, IDictionary<string, object> parameters);
            public override ParameterDescriptor[] GetParameters();

            // Properties
            public override string ActionName { get; }
            public override ControllerDescriptor ControllerDescriptor { get; }
        }
    }
}


Expand Methods
4

1 回答 1

0

ResourceControllerFactory 根据接受 HTTP 标头(我认为)提供自动响应序列化。

于 2010-12-20T14:58:52.177 回答