From ccb5ead450519b64b970e719a5131d11c22e1fe5 Mon Sep 17 00:00:00 2001 From: Ryan Nowak Date: Sun, 20 Sep 2015 19:11:37 -0700 Subject: [PATCH] Api-Review - put uri complexity in CreatedResult --- .../CreatedResult.cs | 21 +++++++++++++++++++ .../Controller.cs | 14 +++++-------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNet.Mvc.Core/CreatedResult.cs b/src/Microsoft.AspNet.Mvc.Core/CreatedResult.cs index 02ac39c398..dc08ad9b2a 100644 --- a/src/Microsoft.AspNet.Mvc.Core/CreatedResult.cs +++ b/src/Microsoft.AspNet.Mvc.Core/CreatedResult.cs @@ -29,6 +29,27 @@ namespace Microsoft.AspNet.Mvc StatusCode = StatusCodes.Status201Created; } + /// + /// Initializes a new instance of the class with the values + /// provided. + /// + /// The location at which the content has been created. + /// The value to format in the entity body. + public CreatedResult([NotNull] Uri location, object value) + : base(value) + { + if (location.IsAbsoluteUri) + { + Location = location.AbsoluteUri; + } + else + { + Location = location.GetComponents(UriComponents.SerializationInfoString, UriFormat.UriEscaped); + } + + StatusCode = StatusCodes.Status201Created; + } + /// /// Gets or sets the location at which the content has been created. /// diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs index 3066cfea15..9784d5d4c2 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs @@ -941,17 +941,13 @@ namespace Microsoft.AspNet.Mvc [NonAction] public virtual CreatedResult Created([NotNull] Uri uri, object value) { - string location; - if (uri.IsAbsoluteUri) + var disposableValue = value as IDisposable; + if (disposableValue != null) { - location = uri.AbsoluteUri; + Response.RegisterForDispose(disposableValue); } - else - { - location = uri.GetComponents(UriComponents.SerializationInfoString, UriFormat.UriEscaped); - } - - return Created(location, value); + + return new CreatedResult(uri, value); } ///