Use Json result constructor only from the Action result helper.

Names to be changed, as they don't make much sense at the moment. Keeping them the same for diffing purposes
This commit is contained in:
Yishai Galatzer 2014-02-04 12:32:26 -08:00
parent 312b4c5fb5
commit 764e5f890d
6 changed files with 22 additions and 13 deletions

View File

@ -42,15 +42,7 @@ namespace MvcSample
public IActionResult UserJson()
{
return new JsonResult(_user)
{
Encoding = Encoding.UTF8
};
}
public IActionResult HelperUserJson()
{
JsonResult jsonResult = (JsonResult)Result.Json(_user);
var jsonResult = Result.Json(_user);
jsonResult.Indent = false;
return jsonResult;

View File

@ -4,6 +4,13 @@ namespace Microsoft.AspNet.Mvc
{
public class ActionResultFactory : IActionResultFactory
{
private readonly IActionResultHelper _result;
public ActionResultFactory(IActionResultHelper result)
{
_result = result;
}
public IActionResult CreateActionResult(Type declaredReturnType, object actionReturnValue, RequestContext requestContext)
{
// optimize common path
@ -45,7 +52,7 @@ namespace Microsoft.AspNet.Mvc
};
}
return new JsonResult(actionReturnValue);
return _result.Json(actionReturnValue);
}
}
}

View File

@ -30,7 +30,7 @@ namespace Microsoft.AspNet.Mvc
};
}
public IActionResult Json(object value)
public IJsonResult Json(object value)
{
return new JsonResult(value);
}

View File

@ -0,0 +1,10 @@
using System.Text;
namespace Microsoft.AspNet.Mvc
{
public interface IJsonResult : IActionResult
{
Encoding Encoding { get; set; }
bool Indent { get; set; }
}
}

View File

@ -7,7 +7,7 @@ using Newtonsoft.Json;
namespace Microsoft.AspNet.Mvc
{
public class JsonResult : IActionResult
public class JsonResult : IJsonResult
{
private readonly object _returnValue;

View File

@ -5,7 +5,7 @@ namespace Microsoft.AspNet.Mvc
{
IActionResult Content(string value);
IActionResult Content(string value, string contentType);
IActionResult Json(object value);
IJsonResult Json(object value);
IActionResult View(string view, ViewData viewData);
}
}