Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/aspnetwebstack.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMikeStall <jmstall@microsoft.com>2012-03-26 20:49:08 +0400
committerMikeStall <jmstall@microsoft.com>2012-03-27 01:33:13 +0400
commit176d7ba8bfc5df4d6a204f4c71f0e5b8f01df1a4 (patch)
tree48b35035596bf47410f1c8315889e439847d450a /src/System.Web.Http
parentd4ca7c24a11bfaec8d8baca5ed9be6674ff8e241 (diff)
387277 - Perf update. Cache HttpActionBinding on actionDescriptor so that we don't need to recompute it every request.
Diffstat (limited to 'src/System.Web.Http')
-rw-r--r--src/System.Web.Http/ApiController.cs3
-rw-r--r--src/System.Web.Http/Controllers/HttpActionBinding.cs10
-rw-r--r--src/System.Web.Http/Controllers/HttpActionDescriptor.cs24
3 files changed, 33 insertions, 4 deletions
diff --git a/src/System.Web.Http/ApiController.cs b/src/System.Web.Http/ApiController.cs
index e0119446..8da857c1 100644
--- a/src/System.Web.Http/ApiController.cs
+++ b/src/System.Web.Http/ApiController.cs
@@ -140,8 +140,7 @@ namespace System.Web.Http
// Func<Task<HttpResponseMessage>>
Task<HttpResponseMessage> result = InvokeActionWithAuthorizationFilters(actionContext, cancellationToken, authorizationFilters, () =>
{
- IActionValueBinder actionValueBinder = controllerDescriptor.ActionValueBinder;
- HttpActionBinding actionBinding = actionValueBinder.GetBinding(actionDescriptor);
+ HttpActionBinding actionBinding = actionDescriptor.ActionBinding;
Task bindTask = actionBinding.ExecuteBindingAsync(actionContext, cancellationToken);
return bindTask.Then<HttpResponseMessage>(() =>
{
diff --git a/src/System.Web.Http/Controllers/HttpActionBinding.cs b/src/System.Web.Http/Controllers/HttpActionBinding.cs
index 5f805509..9ccfc0c3 100644
--- a/src/System.Web.Http/Controllers/HttpActionBinding.cs
+++ b/src/System.Web.Http/Controllers/HttpActionBinding.cs
@@ -19,6 +19,8 @@ namespace System.Web.Http.Controllers
private HttpActionDescriptor _actionDescriptor;
private HttpParameterBinding[] _parameterBindings;
+ private ModelMetadataProvider _metadataProvider;
+
public HttpActionBinding()
{
}
@@ -82,10 +84,14 @@ namespace System.Web.Http.Controllers
}
}
- ModelMetadataProvider metadataProvider = actionContext.ControllerContext.Configuration.ServiceResolver.GetModelMetadataProvider();
+ if (_metadataProvider == null)
+ {
+ HttpConfiguration config = actionContext.ControllerContext.Configuration;
+ _metadataProvider = config.ServiceResolver.GetModelMetadataProvider();
+ }
// Execute all the binders.
- IEnumerable<Task> tasks = from parameterBinder in ParameterBindings select parameterBinder.ExecuteBindingAsync(metadataProvider, actionContext, cancellationToken);
+ IEnumerable<Task> tasks = from parameterBinder in ParameterBindings select parameterBinder.ExecuteBindingAsync(_metadataProvider, actionContext, cancellationToken);
return TaskHelpers.Iterate(tasks, cancellationToken);
}
}
diff --git a/src/System.Web.Http/Controllers/HttpActionDescriptor.cs b/src/System.Web.Http/Controllers/HttpActionDescriptor.cs
index 5be6722d..83f7c067 100644
--- a/src/System.Web.Http/Controllers/HttpActionDescriptor.cs
+++ b/src/System.Web.Http/Controllers/HttpActionDescriptor.cs
@@ -24,6 +24,8 @@ namespace System.Web.Http.Controllers
private HttpControllerDescriptor _controllerDescriptor;
private readonly Collection<HttpMethod> _supportedHttpMethods = new Collection<HttpMethod>();
+ private HttpActionBinding _actionBinding;
+
protected HttpActionDescriptor()
{
}
@@ -54,6 +56,28 @@ namespace System.Web.Http.Controllers
}
}
+ public virtual HttpActionBinding ActionBinding
+ {
+ get
+ {
+ if (_actionBinding == null)
+ {
+ IActionValueBinder actionValueBinder = _controllerDescriptor.ActionValueBinder;
+ HttpActionBinding actionBinding = actionValueBinder.GetBinding(this);
+ _actionBinding = actionBinding;
+ }
+ return _actionBinding;
+ }
+ set
+ {
+ if (value == null)
+ {
+ throw Error.PropertyNull();
+ }
+ _actionBinding = value;
+ }
+ }
+
public HttpControllerDescriptor ControllerDescriptor
{
get { return _controllerDescriptor; }