ASP.NET MVC中的ResourceControllerFactory和DefaultControllerFactory有什么区别?
上下文:我希望将IOC容器挂钩到控制器工厂 - 我之前已经覆盖了DefaultControllerFactory
来执行此操作,但我看到正在使用ResourceControllerFactory
在我目前正在合作的项目中。
是否提供了对REST API的改进支持?
每个代码:
DefaultControllerFactory
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; }
}
ResourceControllerFactory
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
答案 0 :(得分:0)
资源控制器工厂根据接受HTTP标头提供自动响应序列化(我认为)。