Replacing NotNullAttribute with thrown exceptions

This commit is contained in:
Pranav K 2015-09-30 21:04:56 -07:00
parent 02c36a1c48
commit 3a876e387f
184 changed files with 2739 additions and 803 deletions

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal; using System;
namespace Microsoft.AspNet.Mvc.ApiExplorer namespace Microsoft.AspNet.Mvc.ApiExplorer
{ {
@ -17,8 +17,13 @@ namespace Microsoft.AspNet.Mvc.ApiExplorer
/// <typeparam name="T">The type of the property.</typeparam> /// <typeparam name="T">The type of the property.</typeparam>
/// <param name="apiDescription">The <see cref="ApiDescription"/>.</param> /// <param name="apiDescription">The <see cref="ApiDescription"/>.</param>
/// <returns>The property or the default value of <typeparamref name="T"/>.</returns> /// <returns>The property or the default value of <typeparamref name="T"/>.</returns>
public static T GetProperty<T>([NotNull] this ApiDescription apiDescription) public static T GetProperty<T>(this ApiDescription apiDescription)
{ {
if (apiDescription == null)
{
throw new ArgumentNullException(nameof(apiDescription));
}
object value; object value;
if (apiDescription.Properties.TryGetValue(typeof(T), out value)) if (apiDescription.Properties.TryGetValue(typeof(T), out value))
{ {
@ -37,8 +42,18 @@ namespace Microsoft.AspNet.Mvc.ApiExplorer
/// <typeparam name="T">The type of the property.</typeparam> /// <typeparam name="T">The type of the property.</typeparam>
/// <param name="apiDescription">The <see cref="ApiDescription"/>.</param> /// <param name="apiDescription">The <see cref="ApiDescription"/>.</param>
/// <param name="value">The value of the property.</param> /// <param name="value">The value of the property.</param>
public static void SetProperty<T>([NotNull] this ApiDescription apiDescription, [NotNull] T value) public static void SetProperty<T>(this ApiDescription apiDescription, T value)
{ {
if (apiDescription == null)
{
throw new ArgumentNullException(nameof(apiDescription));
}
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
apiDescription.Properties[typeof(T)] = value; apiDescription.Properties[typeof(T)] = value;
} }
} }

View File

@ -1,8 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApiExplorer namespace Microsoft.AspNet.Mvc.ApiExplorer
{ {
@ -16,8 +16,13 @@ namespace Microsoft.AspNet.Mvc.ApiExplorer
/// </summary> /// </summary>
/// <param name="items">The list of <see cref="ApiDescriptionGroup"/>.</param> /// <param name="items">The list of <see cref="ApiDescriptionGroup"/>.</param>
/// <param name="version">The unique version of discovered groups.</param> /// <param name="version">The unique version of discovered groups.</param>
public ApiDescriptionGroupCollection([NotNull] IReadOnlyList<ApiDescriptionGroup> items, int version) public ApiDescriptionGroupCollection(IReadOnlyList<ApiDescriptionGroup> items, int version)
{ {
if (items == null)
{
throw new ArgumentNullException(nameof(items));
}
Items = items; Items = items;
Version = version; Version = version;
} }

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Abstractions; using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApiExplorer namespace Microsoft.AspNet.Mvc.ApiExplorer
{ {
@ -16,8 +16,13 @@ namespace Microsoft.AspNet.Mvc.ApiExplorer
/// Creates a new instance of <see cref="ApiDescriptionProviderContext"/>. /// Creates a new instance of <see cref="ApiDescriptionProviderContext"/>.
/// </summary> /// </summary>
/// <param name="actions">The list of actions.</param> /// <param name="actions">The list of actions.</param>
public ApiDescriptionProviderContext([NotNull] IReadOnlyList<ActionDescriptor> actions) public ApiDescriptionProviderContext(IReadOnlyList<ActionDescriptor> actions)
{ {
if (actions == null)
{
throw new ArgumentNullException(nameof(actions));
}
Actions = actions; Actions = actions;
Results = new List<ApiDescription>(); Results = new List<ApiDescription>();

View File

@ -53,8 +53,13 @@ namespace Microsoft.AspNet.Mvc.ApiExplorer
} }
/// <inheritdoc /> /// <inheritdoc />
public void OnProvidersExecuting([NotNull] ApiDescriptionProviderContext context) public void OnProvidersExecuting(ApiDescriptionProviderContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
foreach (var action in context.Actions.OfType<ControllerActionDescriptor>()) foreach (var action in context.Actions.OfType<ControllerActionDescriptor>())
{ {
var extensionData = action.GetProperty<ApiDescriptionActionData>(); var extensionData = action.GetProperty<ApiDescriptionActionData>();
@ -69,7 +74,7 @@ namespace Microsoft.AspNet.Mvc.ApiExplorer
} }
} }
public void OnProvidersExecuted([NotNull] ApiDescriptionProviderContext context) public void OnProvidersExecuted(ApiDescriptionProviderContext context)
{ {
} }

View File

@ -1,16 +1,21 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Mvc.ApiExplorer; using Microsoft.AspNet.Mvc.ApiExplorer;
using Microsoft.Framework.DependencyInjection.Extensions; using Microsoft.Framework.DependencyInjection.Extensions;
using Microsoft.Framework.Internal;
namespace Microsoft.Framework.DependencyInjection namespace Microsoft.Framework.DependencyInjection
{ {
public static class MvcApiExplorerMvcCoreBuilderExtensions public static class MvcApiExplorerMvcCoreBuilderExtensions
{ {
public static IMvcCoreBuilder AddApiExplorer([NotNull] this IMvcCoreBuilder builder) public static IMvcCoreBuilder AddApiExplorer(this IMvcCoreBuilder builder)
{ {
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
AddApiExplorerServices(builder.Services); AddApiExplorerServices(builder.Services);
return builder; return builder;
} }

View File

@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApiExplorer namespace Microsoft.AspNet.Mvc.ApiExplorer
{ {
public interface IApiDescriptionProvider public interface IApiDescriptionProvider
@ -28,8 +26,8 @@ namespace Microsoft.AspNet.Mvc.ApiExplorer
/// </remarks> /// </remarks>
int Order { get; } int Order { get; }
void OnProvidersExecuting([NotNull] ApiDescriptionProviderContext context); void OnProvidersExecuting(ApiDescriptionProviderContext context);
void OnProvidersExecuted([NotNull] ApiDescriptionProviderContext context); void OnProvidersExecuted(ApiDescriptionProviderContext context);
} }
} }

View File

@ -11,8 +11,7 @@
"dependencies": { "dependencies": {
"Microsoft.AspNet.Mvc.Core": "6.0.0-*", "Microsoft.AspNet.Mvc.Core": "6.0.0-*",
"Microsoft.Framework.PropertyHelper.Sources": { "version": "1.0.0-*", "type": "build" }, "Microsoft.Framework.PropertyHelper.Sources": { "version": "1.0.0-*", "type": "build" },
"Microsoft.Framework.ClosedGenericMatcher.Sources": { "version": "1.0.0-*", "type": "build" }, "Microsoft.Framework.ClosedGenericMatcher.Sources": { "version": "1.0.0-*", "type": "build" }
"Microsoft.Framework.NotNullAttribute.Sources": { "version": "1.0.0-*", "type": "build" }
}, },
"frameworks": { "frameworks": {
"dnx451": { }, "dnx451": { },

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -22,9 +21,13 @@ namespace Microsoft.AspNet.Mvc
/// Initializes a new instance of the <see cref="AcceptVerbsAttribute" /> class. /// Initializes a new instance of the <see cref="AcceptVerbsAttribute" /> class.
/// </summary> /// </summary>
/// <param name="method">The HTTP method the action supports.</param> /// <param name="method">The HTTP method the action supports.</param>
public AcceptVerbsAttribute([NotNull] string method) public AcceptVerbsAttribute(string method)
: this(new string[] { method }) : this(new string[] { method })
{ {
if (method == null)
{
throw new ArgumentNullException(nameof(method));
}
} }
/// <summary> /// <summary>

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ActionConstraints namespace Microsoft.AspNet.Mvc.ActionConstraints
{ {
@ -23,8 +22,13 @@ namespace Microsoft.AspNet.Mvc.ActionConstraints
} }
/// <inheritdoc /> /// <inheritdoc />
public void OnProvidersExecuting([NotNull] ActionConstraintProviderContext context) public void OnProvidersExecuting(ActionConstraintProviderContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
foreach (var item in context.Results) foreach (var item in context.Results)
{ {
ProvideConstraint(item, context.HttpContext.RequestServices); ProvideConstraint(item, context.HttpContext.RequestServices);
@ -32,7 +36,7 @@ namespace Microsoft.AspNet.Mvc.ActionConstraints
} }
/// <inheritdoc /> /// <inheritdoc />
public void OnProvidersExecuted([NotNull] ActionConstraintProviderContext context) public void OnProvidersExecuted(ActionConstraintProviderContext context)
{ {
} }

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Primitives; using Microsoft.Framework.Primitives;
namespace Microsoft.AspNet.Mvc.ActionConstraints namespace Microsoft.AspNet.Mvc.ActionConstraints
@ -21,8 +20,13 @@ namespace Microsoft.AspNet.Mvc.ActionConstraints
private readonly string PreflightHttpMethod = "OPTIONS"; private readonly string PreflightHttpMethod = "OPTIONS";
// Empty collection means any method will be accepted. // Empty collection means any method will be accepted.
public HttpMethodConstraint([NotNull] IEnumerable<string> httpMethods) public HttpMethodConstraint(IEnumerable<string> httpMethods)
{ {
if (httpMethods == null)
{
throw new ArgumentNullException(nameof(httpMethods));
}
var methods = new List<string>(); var methods = new List<string>();
foreach (var method in httpMethods) foreach (var method in httpMethods)
@ -51,8 +55,13 @@ namespace Microsoft.AspNet.Mvc.ActionConstraints
get { return HttpMethodConstraintOrder; } get { return HttpMethodConstraintOrder; }
} }
public bool Accept([NotNull] ActionConstraintContext context) public bool Accept(ActionConstraintContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (_methods.Count == 0) if (_methods.Count == 0)
{ {
return true; return true;

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
@ -8,7 +9,6 @@ using System.Reflection;
using Microsoft.AspNet.Mvc.ActionConstraints; using Microsoft.AspNet.Mvc.ActionConstraints;
using Microsoft.AspNet.Mvc.Filters; using Microsoft.AspNet.Mvc.Filters;
using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApplicationModels namespace Microsoft.AspNet.Mvc.ApplicationModels
{ {
@ -17,9 +17,19 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
public class ActionModel : ICommonModel, IFilterModel, IApiExplorerModel public class ActionModel : ICommonModel, IFilterModel, IApiExplorerModel
{ {
public ActionModel( public ActionModel(
[NotNull] MethodInfo actionMethod, MethodInfo actionMethod,
[NotNull] IReadOnlyList<object> attributes) IReadOnlyList<object> attributes)
{ {
if (actionMethod == null)
{
throw new ArgumentNullException(nameof(actionMethod));
}
if (attributes == null)
{
throw new ArgumentNullException(nameof(attributes));
}
ActionMethod = actionMethod; ActionMethod = actionMethod;
ApiExplorer = new ApiExplorerModel(); ApiExplorer = new ApiExplorerModel();
@ -32,8 +42,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
Properties = new Dictionary<object, object>(); Properties = new Dictionary<object, object>();
} }
public ActionModel([NotNull] ActionModel other) public ActionModel(ActionModel other)
{ {
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}
ActionMethod = other.ActionMethod; ActionMethod = other.ActionMethod;
ActionName = other.ActionName; ActionName = other.ActionName;

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal; using System;
namespace Microsoft.AspNet.Mvc.ApplicationModels namespace Microsoft.AspNet.Mvc.ApplicationModels
{ {
@ -21,8 +21,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// Creates a new <see cref="ApiExplorerModel"/> with properties copied from <paramref name="other"/>. /// Creates a new <see cref="ApiExplorerModel"/> with properties copied from <paramref name="other"/>.
/// </summary> /// </summary>
/// <param name="other">The <see cref="ApiExplorerModel"/> to copy.</param> /// <param name="other">The <see cref="ApiExplorerModel"/> to copy.</param>
public ApiExplorerModel([NotNull] ApiExplorerModel other) public ApiExplorerModel(ApiExplorerModel other)
{ {
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}
GroupName = other.GroupName; GroupName = other.GroupName;
IsVisible = other.IsVisible; IsVisible = other.IsVisible;
} }

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApplicationModels namespace Microsoft.AspNet.Mvc.ApplicationModels
{ {
@ -18,9 +18,19 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// <param name="applicationModel">The <see cref="ApplicationModel"/>.</param> /// <param name="applicationModel">The <see cref="ApplicationModel"/>.</param>
/// <param name="conventions">The set of conventions.</param> /// <param name="conventions">The set of conventions.</param>
public static void ApplyConventions( public static void ApplyConventions(
[NotNull] ApplicationModel applicationModel, ApplicationModel applicationModel,
[NotNull] IEnumerable<IApplicationModelConvention> conventions) IEnumerable<IApplicationModelConvention> conventions)
{ {
if (applicationModel == null)
{
throw new ArgumentNullException(nameof(applicationModel));
}
if (conventions == null)
{
throw new ArgumentNullException(nameof(conventions));
}
// Conventions are applied from the outside-in to allow for scenarios where an action overrides // Conventions are applied from the outside-in to allow for scenarios where an action overrides
// a controller, etc. // a controller, etc.
foreach (var convention in conventions) foreach (var convention in conventions)

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Reflection; using System.Reflection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApplicationModels namespace Microsoft.AspNet.Mvc.ApplicationModels
{ {
@ -12,8 +12,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// </summary> /// </summary>
public class ApplicationModelProviderContext public class ApplicationModelProviderContext
{ {
public ApplicationModelProviderContext([NotNull] IEnumerable<TypeInfo> controllerTypes) public ApplicationModelProviderContext(IEnumerable<TypeInfo> controllerTypes)
{ {
if (controllerTypes == null)
{
throw new ArgumentNullException(nameof(controllerTypes));
}
ControllerTypes = controllerTypes; ControllerTypes = controllerTypes;
} }

View File

@ -7,7 +7,6 @@ using System.Linq;
using System.Text; using System.Text;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApplicationModels namespace Microsoft.AspNet.Mvc.ApplicationModels
{ {
@ -19,16 +18,26 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
{ {
} }
public AttributeRouteModel([NotNull] IRouteTemplateProvider templateProvider) public AttributeRouteModel(IRouteTemplateProvider templateProvider)
{ {
if (templateProvider == null)
{
throw new ArgumentNullException(nameof(templateProvider));
}
Attribute = templateProvider; Attribute = templateProvider;
Template = templateProvider.Template; Template = templateProvider.Template;
Order = templateProvider.Order; Order = templateProvider.Order;
Name = templateProvider.Name; Name = templateProvider.Name;
} }
public AttributeRouteModel([NotNull] AttributeRouteModel other) public AttributeRouteModel(AttributeRouteModel other)
{ {
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}
Attribute = other.Attribute; Attribute = other.Attribute;
Name = other.Name; Name = other.Name;
Order = other.Order; Order = other.Order;

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Authorization; using Microsoft.AspNet.Authorization;
using Microsoft.AspNet.Mvc.Filters; using Microsoft.AspNet.Mvc.Filters;
using Microsoft.Framework.Internal;
using Microsoft.Framework.OptionsModel; using Microsoft.Framework.OptionsModel;
namespace Microsoft.AspNet.Mvc.ApplicationModels namespace Microsoft.AspNet.Mvc.ApplicationModels
@ -18,15 +18,20 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
_authorizationOptions = authorizationOptionsAccessor.Value; _authorizationOptions = authorizationOptionsAccessor.Value;
} }
public int Order { get { return -1000 + 10; } } public int Order { get { return -1000 + 10; } }
public void OnProvidersExecuted([NotNull]ApplicationModelProviderContext context) public void OnProvidersExecuted(ApplicationModelProviderContext context)
{ {
// Intentionally empty. // Intentionally empty.
} }
public void OnProvidersExecuting([NotNull]ApplicationModelProviderContext context) public void OnProvidersExecuting(ApplicationModelProviderContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
AuthorizationPolicy policy; AuthorizationPolicy policy;
foreach (var controllerModel in context.Result.Controllers) foreach (var controllerModel in context.Result.Controllers)

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
@ -8,7 +9,6 @@ using System.Reflection;
using Microsoft.AspNet.Mvc.ActionConstraints; using Microsoft.AspNet.Mvc.ActionConstraints;
using Microsoft.AspNet.Mvc.Filters; using Microsoft.AspNet.Mvc.Filters;
using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApplicationModels namespace Microsoft.AspNet.Mvc.ApplicationModels
{ {
@ -17,9 +17,19 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
public class ControllerModel : ICommonModel, IFilterModel, IApiExplorerModel public class ControllerModel : ICommonModel, IFilterModel, IApiExplorerModel
{ {
public ControllerModel( public ControllerModel(
[NotNull] TypeInfo controllerType, TypeInfo controllerType,
[NotNull] IReadOnlyList<object> attributes) IReadOnlyList<object> attributes)
{ {
if (controllerType == null)
{
throw new ArgumentNullException(nameof(controllerType));
}
if (attributes == null)
{
throw new ArgumentNullException(nameof(attributes));
}
ControllerType = controllerType; ControllerType = controllerType;
Actions = new List<ActionModel>(); Actions = new List<ActionModel>();
@ -33,8 +43,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
ControllerProperties = new List<PropertyModel>(); ControllerProperties = new List<PropertyModel>();
} }
public ControllerModel([NotNull] ControllerModel other) public ControllerModel(ControllerModel other)
{ {
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}
ControllerName = other.ControllerName; ControllerName = other.ControllerName;
ControllerType = other.ControllerType; ControllerType = other.ControllerType;

View File

@ -1,17 +1,15 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.AspNet.Mvc.ActionConstraints; using Microsoft.AspNet.Mvc.ActionConstraints;
using Microsoft.AspNet.Mvc.ApiExplorer; using Microsoft.AspNet.Mvc.ApiExplorer;
using Microsoft.AspNet.Mvc.Filters; using Microsoft.AspNet.Mvc.Filters;
using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Framework.OptionsModel; using Microsoft.Framework.OptionsModel;
@ -36,8 +34,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
} }
/// <inheritdoc /> /// <inheritdoc />
public virtual void OnProvidersExecuting([NotNull] ApplicationModelProviderContext context) public virtual void OnProvidersExecuting(ApplicationModelProviderContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
foreach (var filter in _globalFilters) foreach (var filter in _globalFilters)
{ {
context.Result.Filters.Add(filter); context.Result.Filters.Add(filter);
@ -92,7 +95,7 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
} }
/// <inheritdoc /> /// <inheritdoc />
public virtual void OnProvidersExecuted([NotNull] ApplicationModelProviderContext context) public virtual void OnProvidersExecuted(ApplicationModelProviderContext context)
{ {
// Intentionally empty. // Intentionally empty.
} }
@ -105,8 +108,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// A set of <see cref="ControllerModel"/> instances for the given controller <see cref="TypeInfo"/> or /// A set of <see cref="ControllerModel"/> instances for the given controller <see cref="TypeInfo"/> or
/// <c>null</c> if the <paramref name="typeInfo"/> does not represent a controller. /// <c>null</c> if the <paramref name="typeInfo"/> does not represent a controller.
/// </returns> /// </returns>
protected virtual IEnumerable<ControllerModel> BuildControllerModels([NotNull] TypeInfo typeInfo) protected virtual IEnumerable<ControllerModel> BuildControllerModels(TypeInfo typeInfo)
{ {
if (typeInfo == null)
{
throw new ArgumentNullException(nameof(typeInfo));
}
var controllerModel = CreateControllerModel(typeInfo); var controllerModel = CreateControllerModel(typeInfo);
yield return controllerModel; yield return controllerModel;
} }
@ -116,8 +124,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// </summary> /// </summary>
/// <param name="typeInfo">The <see cref="TypeInfo"/>.</param> /// <param name="typeInfo">The <see cref="TypeInfo"/>.</param>
/// <returns>A <see cref="ControllerModel"/> for the given <see cref="TypeInfo"/>.</returns> /// <returns>A <see cref="ControllerModel"/> for the given <see cref="TypeInfo"/>.</returns>
protected virtual ControllerModel CreateControllerModel([NotNull] TypeInfo typeInfo) protected virtual ControllerModel CreateControllerModel(TypeInfo typeInfo)
{ {
if (typeInfo == null)
{
throw new ArgumentNullException(nameof(typeInfo));
}
// For attribute routes on a controller, we want want to support 'overriding' routes on a derived // For attribute routes on a controller, we want want to support 'overriding' routes on a derived
// class. So we need to walk up the hierarchy looking for the first class to define routes. // class. So we need to walk up the hierarchy looking for the first class to define routes.
// //
@ -214,8 +227,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// </summary> /// </summary>
/// <param name="propertyInfo">The <see cref="PropertyInfo"/>.</param> /// <param name="propertyInfo">The <see cref="PropertyInfo"/>.</param>
/// <returns>A <see cref="PropertyModel"/> for the given <see cref="PropertyInfo"/>.</returns> /// <returns>A <see cref="PropertyModel"/> for the given <see cref="PropertyInfo"/>.</returns>
protected virtual PropertyModel CreatePropertyModel([NotNull] PropertyInfo propertyInfo) protected virtual PropertyModel CreatePropertyModel(PropertyInfo propertyInfo)
{ {
if (propertyInfo == null)
{
throw new ArgumentNullException(nameof(propertyInfo));
}
// CoreCLR returns IEnumerable<Attribute> from GetCustomAttributes - the OfType<object> // CoreCLR returns IEnumerable<Attribute> from GetCustomAttributes - the OfType<object>
// is needed to so that the result of ToArray() is object // is needed to so that the result of ToArray() is object
var attributes = propertyInfo.GetCustomAttributes(inherit: true).OfType<object>().ToArray(); var attributes = propertyInfo.GetCustomAttributes(inherit: true).OfType<object>().ToArray();
@ -239,9 +257,19 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// <c>null</c> if the <paramref name="methodInfo"/> does not represent an action. /// <c>null</c> if the <paramref name="methodInfo"/> does not represent an action.
/// </returns> /// </returns>
protected virtual IEnumerable<ActionModel> BuildActionModels( protected virtual IEnumerable<ActionModel> BuildActionModels(
[NotNull] TypeInfo typeInfo, TypeInfo typeInfo,
[NotNull] MethodInfo methodInfo) MethodInfo methodInfo)
{ {
if (typeInfo == null)
{
throw new ArgumentNullException(nameof(typeInfo));
}
if (methodInfo == null)
{
throw new ArgumentNullException(nameof(methodInfo));
}
if (!IsAction(typeInfo, methodInfo)) if (!IsAction(typeInfo, methodInfo))
{ {
return Enumerable.Empty<ActionModel>(); return Enumerable.Empty<ActionModel>();
@ -436,8 +464,18 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// <remarks> /// <remarks>
/// Override this method to provide custom logic to determine which methods are considered actions. /// Override this method to provide custom logic to determine which methods are considered actions.
/// </remarks> /// </remarks>
protected virtual bool IsAction([NotNull] TypeInfo typeInfo, [NotNull] MethodInfo methodInfo) protected virtual bool IsAction(TypeInfo typeInfo, MethodInfo methodInfo)
{ {
if (typeInfo == null)
{
throw new ArgumentNullException(nameof(typeInfo));
}
if (methodInfo == null)
{
throw new ArgumentNullException(nameof(methodInfo));
}
// The SpecialName bit is set to flag members that are treated in a special way by some compilers // The SpecialName bit is set to flag members that are treated in a special way by some compilers
// (such as property accessors and operator overloading methods). // (such as property accessors and operator overloading methods).
if (methodInfo.IsSpecialName) if (methodInfo.IsSpecialName)
@ -500,9 +538,19 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// the action being created. /// the action being created.
/// </remarks> /// </remarks>
protected virtual ActionModel CreateActionModel( protected virtual ActionModel CreateActionModel(
[NotNull] MethodInfo methodInfo, MethodInfo methodInfo,
[NotNull] IReadOnlyList<object> attributes) IReadOnlyList<object> attributes)
{ {
if (methodInfo == null)
{
throw new ArgumentNullException(nameof(methodInfo));
}
if (attributes == null)
{
throw new ArgumentNullException(nameof(attributes));
}
var actionModel = new ActionModel(methodInfo, attributes); var actionModel = new ActionModel(methodInfo, attributes);
AddRange(actionModel.ActionConstraints, attributes.OfType<IActionConstraintMetadata>()); AddRange(actionModel.ActionConstraints, attributes.OfType<IActionConstraintMetadata>());
@ -558,8 +606,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// </summary> /// </summary>
/// <param name="parameterInfo">The <see cref="ParameterInfo"/>.</param> /// <param name="parameterInfo">The <see cref="ParameterInfo"/>.</param>
/// <returns>A <see cref="ParameterModel"/> for the given <see cref="ParameterInfo"/>.</returns> /// <returns>A <see cref="ParameterModel"/> for the given <see cref="ParameterInfo"/>.</returns>
protected virtual ParameterModel CreateParameterModel([NotNull] ParameterInfo parameterInfo) protected virtual ParameterModel CreateParameterModel(ParameterInfo parameterInfo)
{ {
if (parameterInfo == null)
{
throw new ArgumentNullException(nameof(parameterInfo));
}
// CoreCLR returns IEnumerable<Attribute> from GetCustomAttributes - the OfType<object> // CoreCLR returns IEnumerable<Attribute> from GetCustomAttributes - the OfType<object>
// is needed to so that the result of ToArray() is object // is needed to so that the result of ToArray() is object
var attributes = parameterInfo.GetCustomAttributes(inherit: true).OfType<object>().ToArray(); var attributes = parameterInfo.GetCustomAttributes(inherit: true).OfType<object>().ToArray();

View File

@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApplicationModels namespace Microsoft.AspNet.Mvc.ApplicationModels
{ {
/// <summary> /// <summary>
@ -22,6 +20,6 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// Called to apply the convention to the <see cref="ActionModel"/>. /// Called to apply the convention to the <see cref="ActionModel"/>.
/// </summary> /// </summary>
/// <param name="action">The <see cref="ActionModel"/>.</param> /// <param name="action">The <see cref="ActionModel"/>.</param>
void Apply([NotNull] ActionModel action); void Apply(ActionModel action);
} }
} }

View File

@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApplicationModels namespace Microsoft.AspNet.Mvc.ApplicationModels
{ {
/// <summary> /// <summary>
@ -21,6 +19,6 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// Called to apply the convention to the <see cref="ApplicationModel"/>. /// Called to apply the convention to the <see cref="ApplicationModel"/>.
/// </summary> /// </summary>
/// <param name="application">The <see cref="ApplicationModel"/>.</param> /// <param name="application">The <see cref="ApplicationModel"/>.</param>
void Apply([NotNull] ApplicationModel application); void Apply(ApplicationModel application);
} }
} }

View File

@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApplicationModels namespace Microsoft.AspNet.Mvc.ApplicationModels
{ {
/// <summary> /// <summary>
@ -35,12 +33,12 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// Executed for the first pass of <see cref="ApplicationModel"/> building. See <see cref="Order"/>. /// Executed for the first pass of <see cref="ApplicationModel"/> building. See <see cref="Order"/>.
/// </summary> /// </summary>
/// <param name="context">The <see cref="ApplicationModelProviderContext"/>.</param> /// <param name="context">The <see cref="ApplicationModelProviderContext"/>.</param>
void OnProvidersExecuting([NotNull] ApplicationModelProviderContext context); void OnProvidersExecuting(ApplicationModelProviderContext context);
/// <summary> /// <summary>
/// Executed for the second pass of <see cref="ApplicationModel"/> building. See <see cref="Order"/>. /// Executed for the second pass of <see cref="ApplicationModel"/> building. See <see cref="Order"/>.
/// </summary> /// </summary>
/// <param name="context">The <see cref="ApplicationModelProviderContext"/>.</param> /// <param name="context">The <see cref="ApplicationModelProviderContext"/>.</param>
void OnProvidersExecuted([NotNull] ApplicationModelProviderContext context); void OnProvidersExecuted(ApplicationModelProviderContext context);
} }
} }

View File

@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApplicationModels namespace Microsoft.AspNet.Mvc.ApplicationModels
{ {
/// <summary> /// <summary>
@ -22,6 +20,6 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// Called to apply the convention to the <see cref="ControllerModel"/>. /// Called to apply the convention to the <see cref="ControllerModel"/>.
/// </summary> /// </summary>
/// <param name="controller">The <see cref="ControllerModel"/>.</param> /// <param name="controller">The <see cref="ControllerModel"/>.</param>
void Apply([NotNull] ControllerModel controller); void Apply(ControllerModel controller);
} }
} }

View File

@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApplicationModels namespace Microsoft.AspNet.Mvc.ApplicationModels
{ {
/// <summary> /// <summary>
@ -21,6 +19,6 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// Called to apply the convention to the <see cref="ParameterModel"/>. /// Called to apply the convention to the <see cref="ParameterModel"/>.
/// </summary> /// </summary>
/// <param name="parameter">The <see cref="ParameterModel"/>.</param> /// <param name="parameter">The <see cref="ParameterModel"/>.</param>
void Apply([NotNull] ParameterModel parameter); void Apply(ParameterModel parameter);
} }
} }

View File

@ -1,11 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Reflection; using System.Reflection;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApplicationModels namespace Microsoft.AspNet.Mvc.ApplicationModels
{ {
@ -13,16 +13,31 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
public class ParameterModel : ICommonModel, IBindingModel public class ParameterModel : ICommonModel, IBindingModel
{ {
public ParameterModel( public ParameterModel(
[NotNull] ParameterInfo parameterInfo, ParameterInfo parameterInfo,
[NotNull] IReadOnlyList<object> attributes) IReadOnlyList<object> attributes)
{ {
if (parameterInfo == null)
{
throw new ArgumentNullException(nameof(parameterInfo));
}
if (attributes == null)
{
throw new ArgumentNullException(nameof(attributes));
}
ParameterInfo = parameterInfo; ParameterInfo = parameterInfo;
Properties = new Dictionary<object, object>(); Properties = new Dictionary<object, object>();
Attributes = new List<object>(attributes); Attributes = new List<object>(attributes);
} }
public ParameterModel([NotNull] ParameterModel other) public ParameterModel(ParameterModel other)
{ {
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}
Action = other.Action; Action = other.Action;
Attributes = new List<object>(other.Attributes); Attributes = new List<object>(other.Attributes);
BindingInfo = other.BindingInfo == null ? null : new BindingInfo(other.BindingInfo); BindingInfo = other.BindingInfo == null ? null : new BindingInfo(other.BindingInfo);

View File

@ -1,11 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Reflection; using System.Reflection;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ApplicationModels namespace Microsoft.AspNet.Mvc.ApplicationModels
{ {
@ -21,9 +21,19 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// <param name="propertyInfo">The <see cref="PropertyInfo"/> for the underlying property.</param> /// <param name="propertyInfo">The <see cref="PropertyInfo"/> for the underlying property.</param>
/// <param name="attributes">Any attributes which are annotated on the property.</param> /// <param name="attributes">Any attributes which are annotated on the property.</param>
public PropertyModel( public PropertyModel(
[NotNull] PropertyInfo propertyInfo, PropertyInfo propertyInfo,
[NotNull] IReadOnlyList<object> attributes) IReadOnlyList<object> attributes)
{ {
if (propertyInfo == null)
{
throw new ArgumentNullException(nameof(propertyInfo));
}
if (attributes == null)
{
throw new ArgumentNullException(nameof(attributes));
}
PropertyInfo = propertyInfo; PropertyInfo = propertyInfo;
Properties = new Dictionary<object, object>(); Properties = new Dictionary<object, object>();
Attributes = new List<object>(attributes); Attributes = new List<object>(attributes);
@ -33,8 +43,13 @@ namespace Microsoft.AspNet.Mvc.ApplicationModels
/// Creats a new instance of <see cref="PropertyModel"/> from a given <see cref="PropertyModel"/>. /// Creats a new instance of <see cref="PropertyModel"/> from a given <see cref="PropertyModel"/>.
/// </summary> /// </summary>
/// <param name="other">The <see cref="PropertyModel"/> which needs to be copied.</param> /// <param name="other">The <see cref="PropertyModel"/> which needs to be copied.</param>
public PropertyModel([NotNull] PropertyModel other) public PropertyModel(PropertyModel other)
{ {
if (other == null)
{
throw new ArgumentNullException(nameof(other));
}
Controller = other.Controller; Controller = other.Controller;
Attributes = new List<object>(other.Attributes); Attributes = new List<object>(other.Attributes);
BindingInfo = BindingInfo == null ? null : new BindingInfo(other.BindingInfo); BindingInfo = BindingInfo == null ? null : new BindingInfo(other.BindingInfo);

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -26,9 +26,14 @@ namespace Microsoft.AspNet.Mvc
/// Creates a new <see cref="BadRequestObjectResult"/> instance. /// Creates a new <see cref="BadRequestObjectResult"/> instance.
/// </summary> /// </summary>
/// <param name="modelState"><see cref="ModelStateDictionary"/> containing the validation errors.</param> /// <param name="modelState"><see cref="ModelStateDictionary"/> containing the validation errors.</param>
public BadRequestObjectResult([NotNull] ModelStateDictionary modelState) public BadRequestObjectResult(ModelStateDictionary modelState)
: base(new SerializableError(modelState)) : base(new SerializableError(modelState))
{ {
if (modelState == null)
{
throw new ArgumentNullException(nameof(modelState));
}
StatusCode = StatusCodes.Status400BadRequest; StatusCode = StatusCodes.Status400BadRequest;
} }
} }

View File

@ -8,7 +8,6 @@ using System.Reflection;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -46,8 +45,13 @@ namespace Microsoft.AspNet.Mvc
/// <param name="predicateProviderType">The type which implements /// <param name="predicateProviderType">The type which implements
/// <see cref="IPropertyBindingPredicateProvider"/>. /// <see cref="IPropertyBindingPredicateProvider"/>.
/// </param> /// </param>
public BindAttribute([NotNull] Type predicateProviderType) public BindAttribute(Type predicateProviderType)
{ {
if (predicateProviderType == null)
{
throw new ArgumentNullException(nameof(predicateProviderType));
}
if (!typeof(IPropertyBindingPredicateProvider).GetTypeInfo() if (!typeof(IPropertyBindingPredicateProvider).GetTypeInfo()
.IsAssignableFrom(predicateProviderType.GetTypeInfo())) .IsAssignableFrom(predicateProviderType.GetTypeInfo()))
{ {

View File

@ -6,7 +6,6 @@ using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.AspNet.Mvc.Internal; using Microsoft.AspNet.Mvc.Internal;
using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.Routing;
using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Builder namespace Microsoft.AspNet.Builder
{ {
@ -22,8 +21,13 @@ namespace Microsoft.AspNet.Builder
/// <returns>The <paramref name="app"/>.</returns> /// <returns>The <paramref name="app"/>.</returns>
/// <remarks>This method only supports attribute routing. To add conventional routes use /// <remarks>This method only supports attribute routing. To add conventional routes use
/// <see cref="UseMvc(IApplicationBuilder, Action{IRouteBuilder})"/>.</remarks> /// <see cref="UseMvc(IApplicationBuilder, Action{IRouteBuilder})"/>.</remarks>
public static IApplicationBuilder UseMvc([NotNull] this IApplicationBuilder app) public static IApplicationBuilder UseMvc(this IApplicationBuilder app)
{ {
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
return app.UseMvc(routes => return app.UseMvc(routes =>
{ {
}); });
@ -36,8 +40,13 @@ namespace Microsoft.AspNet.Builder
/// </summary> /// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/>.</param> /// <param name="app">The <see cref="IApplicationBuilder"/>.</param>
/// <returns>The <paramref name="app"/>.</returns> /// <returns>The <paramref name="app"/>.</returns>
public static IApplicationBuilder UseMvcWithDefaultRoute([NotNull] this IApplicationBuilder app) public static IApplicationBuilder UseMvcWithDefaultRoute(this IApplicationBuilder app)
{ {
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
return app.UseMvc(routes => return app.UseMvc(routes =>
{ {
routes.MapRoute( routes.MapRoute(
@ -53,9 +62,19 @@ namespace Microsoft.AspNet.Builder
/// <param name="configureRoutes">A callback to configure MVC routes.</param> /// <param name="configureRoutes">A callback to configure MVC routes.</param>
/// <returns>The <paramref name="app"/>.</returns> /// <returns>The <paramref name="app"/>.</returns>
public static IApplicationBuilder UseMvc( public static IApplicationBuilder UseMvc(
[NotNull] this IApplicationBuilder app, this IApplicationBuilder app,
[NotNull] Action<IRouteBuilder> configureRoutes) Action<IRouteBuilder> configureRoutes)
{ {
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
if (configureRoutes == null)
{
throw new ArgumentNullException(nameof(configureRoutes));
}
// Verify if AddMvc was done before calling UseMvc // Verify if AddMvc was done before calling UseMvc
// We use the MvcMarkerService to make sure if all the services were added. // We use the MvcMarkerService to make sure if all the services were added.
MvcServicesHelper.ThrowIfMvcNotRegistered(app.ApplicationServices); MvcServicesHelper.ThrowIfMvcNotRegistered(app.ApplicationServices);

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http.Authentication; using Microsoft.AspNet.Http.Authentication;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -45,8 +45,13 @@ namespace Microsoft.AspNet.Mvc
public AuthenticationProperties Properties { get; set; } public AuthenticationProperties Properties { get; set; }
public override async Task ExecuteResultAsync([NotNull] ActionContext context) public override async Task ExecuteResultAsync(ActionContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var auth = context.HttpContext.Authentication; var auth = context.HttpContext.Authentication;
if (AuthenticationSchemes.Count > 0) if (AuthenticationSchemes.Count > 0)
{ {

View File

@ -8,7 +8,6 @@ using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.AspNet.Mvc.ActionConstraints; using Microsoft.AspNet.Mvc.ActionConstraints;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Filters; using Microsoft.AspNet.Mvc.Filters;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
@ -24,8 +23,13 @@ namespace Microsoft.AspNet.Mvc
/// <summary> /// <summary>
/// Creates a new instance of <see cref="ConsumesAttribute"/>. /// Creates a new instance of <see cref="ConsumesAttribute"/>.
/// </summary> /// </summary>
public ConsumesAttribute([NotNull] string contentType, params string[] otherContentTypes) public ConsumesAttribute(string contentType, params string[] otherContentTypes)
{ {
if (contentType == null)
{
throw new ArgumentNullException(nameof(contentType));
}
ContentTypes = GetContentTypes(contentType, otherContentTypes); ContentTypes = GetContentTypes(contentType, otherContentTypes);
} }
@ -38,8 +42,13 @@ namespace Microsoft.AspNet.Mvc
public IList<MediaTypeHeaderValue> ContentTypes { get; set; } public IList<MediaTypeHeaderValue> ContentTypes { get; set; }
/// <inheritdoc /> /// <inheritdoc />
public void OnResourceExecuting([NotNull] ResourceExecutingContext context) public void OnResourceExecuting(ResourceExecutingContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
// Only execute if the current filter is the one which is closest to the action. // Only execute if the current filter is the one which is closest to the action.
// Ignore all other filters. This is to ensure we have a overriding behavior. // Ignore all other filters. This is to ensure we have a overriding behavior.
if (IsApplicable(context.ActionDescriptor)) if (IsApplicable(context.ActionDescriptor))
@ -58,8 +67,12 @@ namespace Microsoft.AspNet.Mvc
} }
/// <inheritdoc /> /// <inheritdoc />
public void OnResourceExecuted([NotNull] ResourceExecutedContext context) public void OnResourceExecuted(ResourceExecutedContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
} }
public bool Accept(ActionConstraintContext context) public bool Accept(ActionConstraintContext context)

View File

@ -1,12 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features;
using Microsoft.AspNet.Mvc.Internal; using Microsoft.AspNet.Mvc.Internal;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
@ -33,8 +33,13 @@ namespace Microsoft.AspNet.Mvc
/// </summary> /// </summary>
public int? StatusCode { get; set; } public int? StatusCode { get; set; }
public override Task ExecuteResultAsync([NotNull] ActionContext context) public override Task ExecuteResultAsync(ActionContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var response = context.HttpContext.Response; var response = context.HttpContext.Response;
var contentTypeHeader = ContentType; var contentTypeHeader = ContentType;

View File

@ -1,11 +1,11 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Mvc.Abstractions; using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.AspNet.Mvc.ApplicationModels; using Microsoft.AspNet.Mvc.ApplicationModels;
using Microsoft.Framework.Internal;
using Microsoft.Framework.OptionsModel; using Microsoft.Framework.OptionsModel;
namespace Microsoft.AspNet.Mvc.Controllers namespace Microsoft.AspNet.Mvc.Controllers
@ -17,10 +17,25 @@ namespace Microsoft.AspNet.Mvc.Controllers
private readonly IEnumerable<IApplicationModelConvention> _conventions; private readonly IEnumerable<IApplicationModelConvention> _conventions;
public ControllerActionDescriptorProvider( public ControllerActionDescriptorProvider(
[NotNull] IControllerTypeProvider controllerTypeProvider, IControllerTypeProvider controllerTypeProvider,
[NotNull] IEnumerable<IApplicationModelProvider> applicationModelProviders, IEnumerable<IApplicationModelProvider> applicationModelProviders,
[NotNull] IOptions<MvcOptions> optionsAccessor) IOptions<MvcOptions> optionsAccessor)
{ {
if (controllerTypeProvider == null)
{
throw new ArgumentNullException(nameof(controllerTypeProvider));
}
if (applicationModelProviders == null)
{
throw new ArgumentNullException(nameof(applicationModelProviders));
}
if (optionsAccessor == null)
{
throw new ArgumentNullException(nameof(optionsAccessor));
}
_controllerTypeProvider = controllerTypeProvider; _controllerTypeProvider = controllerTypeProvider;
_applicationModelProviders = applicationModelProviders.OrderBy(p => p.Order).ToArray(); _applicationModelProviders = applicationModelProviders.OrderBy(p => p.Order).ToArray();
_conventions = optionsAccessor.Value.Conventions; _conventions = optionsAccessor.Value.Conventions;
@ -32,8 +47,13 @@ namespace Microsoft.AspNet.Mvc.Controllers
} }
/// <inheritdoc /> /// <inheritdoc />
public void OnProvidersExecuting ([NotNull] ActionDescriptorProviderContext context) public void OnProvidersExecuting(ActionDescriptorProviderContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
foreach (var descriptor in GetDescriptors()) foreach (var descriptor in GetDescriptors())
{ {
context.Results.Add(descriptor); context.Results.Add(descriptor);
@ -41,7 +61,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
} }
/// <inheritdoc /> /// <inheritdoc />
public void OnProvidersExecuted([NotNull] ActionDescriptorProviderContext context) public void OnProvidersExecuted(ActionDescriptorProviderContext context)
{ {
} }
@ -62,7 +82,7 @@ namespace Microsoft.AspNet.Mvc.Controllers
_applicationModelProviders[i].OnProvidersExecuting(context); _applicationModelProviders[i].OnProvidersExecuting(context);
} }
for (var i = _applicationModelProviders.Length - 1 ; i >= 0; i--) for (var i = _applicationModelProviders.Length - 1; i >= 0; i--)
{ {
_applicationModelProviders[i].OnProvidersExecuted(context); _applicationModelProviders[i].OnProvidersExecuted(context);
} }

View File

@ -25,19 +25,19 @@ namespace Microsoft.AspNet.Mvc.Controllers
private readonly IControllerActionArgumentBinder _argumentBinder; private readonly IControllerActionArgumentBinder _argumentBinder;
public ControllerActionInvoker( public ControllerActionInvoker(
[NotNull] ActionContext actionContext, ActionContext actionContext,
[NotNull] IReadOnlyList<IFilterProvider> filterProviders, IReadOnlyList<IFilterProvider> filterProviders,
[NotNull] IControllerFactory controllerFactory, IControllerFactory controllerFactory,
[NotNull] ControllerActionDescriptor descriptor, ControllerActionDescriptor descriptor,
[NotNull] IReadOnlyList<IInputFormatter> inputFormatters, IReadOnlyList<IInputFormatter> inputFormatters,
[NotNull] IReadOnlyList<IOutputFormatter> outputFormatters, IReadOnlyList<IOutputFormatter> outputFormatters,
[NotNull] IControllerActionArgumentBinder controllerActionArgumentBinder, IControllerActionArgumentBinder controllerActionArgumentBinder,
[NotNull] IReadOnlyList<IModelBinder> modelBinders, IReadOnlyList<IModelBinder> modelBinders,
[NotNull] IReadOnlyList<IModelValidatorProvider> modelValidatorProviders, IReadOnlyList<IModelValidatorProvider> modelValidatorProviders,
[NotNull] IReadOnlyList<IValueProviderFactory> valueProviderFactories, IReadOnlyList<IValueProviderFactory> valueProviderFactories,
[NotNull] IActionBindingContextAccessor actionBindingContextAccessor, IActionBindingContextAccessor actionBindingContextAccessor,
[NotNull] ILogger logger, ILogger logger,
[NotNull] TelemetrySource telemetry, TelemetrySource telemetry,
int maxModelValidationErrors) int maxModelValidationErrors)
: base( : base(
actionContext, actionContext,
@ -52,6 +52,71 @@ namespace Microsoft.AspNet.Mvc.Controllers
telemetry, telemetry,
maxModelValidationErrors) maxModelValidationErrors)
{ {
if (actionContext == null)
{
throw new ArgumentNullException(nameof(actionContext));
}
if (filterProviders == null)
{
throw new ArgumentNullException(nameof(filterProviders));
}
if (controllerFactory == null)
{
throw new ArgumentNullException(nameof(controllerFactory));
}
if (descriptor == null)
{
throw new ArgumentNullException(nameof(descriptor));
}
if (inputFormatters == null)
{
throw new ArgumentNullException(nameof(inputFormatters));
}
if (outputFormatters == null)
{
throw new ArgumentNullException(nameof(outputFormatters));
}
if (controllerActionArgumentBinder == null)
{
throw new ArgumentNullException(nameof(controllerActionArgumentBinder));
}
if (modelBinders == null)
{
throw new ArgumentNullException(nameof(modelBinders));
}
if (modelValidatorProviders == null)
{
throw new ArgumentNullException(nameof(modelValidatorProviders));
}
if (valueProviderFactories == null)
{
throw new ArgumentNullException(nameof(valueProviderFactories));
}
if (actionBindingContextAccessor == null)
{
throw new ArgumentNullException(nameof(actionBindingContextAccessor));
}
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}
if (telemetry == null)
{
throw new ArgumentNullException(nameof(telemetry));
}
_descriptor = descriptor; _descriptor = descriptor;
_controllerFactory = controllerFactory; _controllerFactory = controllerFactory;
_argumentBinder = controllerActionArgumentBinder; _argumentBinder = controllerActionArgumentBinder;
@ -95,12 +160,27 @@ namespace Microsoft.AspNet.Mvc.Controllers
ActionContext context, ActionContext context,
ActionBindingContext bindingContext) ActionBindingContext bindingContext)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (bindingContext == null)
{
throw new ArgumentNullException(nameof(bindingContext));
}
return _argumentBinder.BindActionArgumentsAsync(context, bindingContext, Instance); return _argumentBinder.BindActionArgumentsAsync(context, bindingContext, Instance);
} }
// Marking as internal for Unit Testing purposes. // Marking as internal for Unit Testing purposes.
internal static IActionResult CreateActionResult([NotNull] Type declaredReturnType, object actionReturnValue) internal static IActionResult CreateActionResult(Type declaredReturnType, object actionReturnValue)
{ {
if (declaredReturnType == null)
{
throw new ArgumentNullException(nameof(declaredReturnType));
}
// optimize common path // optimize common path
var actionResult = actionReturnValue as IActionResult; var actionResult = actionReturnValue as IActionResult;
if (actionResult != null) if (actionResult != null)

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics.Tracing; using System.Diagnostics.Tracing;
using System.Linq; using System.Linq;
@ -10,7 +11,6 @@ using Microsoft.AspNet.Mvc.Formatters;
using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.ModelBinding.Validation; using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
using Microsoft.Framework.OptionsModel; using Microsoft.Framework.OptionsModel;
@ -60,32 +60,37 @@ namespace Microsoft.AspNet.Mvc.Controllers
} }
/// <inheritdoc /> /// <inheritdoc />
public void OnProvidersExecuting([NotNull] ActionInvokerProviderContext context) public void OnProvidersExecuting(ActionInvokerProviderContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var actionDescriptor = context.ActionContext.ActionDescriptor as ControllerActionDescriptor; var actionDescriptor = context.ActionContext.ActionDescriptor as ControllerActionDescriptor;
if (actionDescriptor != null) if (actionDescriptor != null)
{ {
context.Result = new ControllerActionInvoker( context.Result = new ControllerActionInvoker(
context.ActionContext, context.ActionContext,
_filterProviders, _filterProviders,
_controllerFactory, _controllerFactory,
actionDescriptor, actionDescriptor,
_inputFormatters, _inputFormatters,
_outputFormatters, _outputFormatters,
_argumentBinder, _argumentBinder,
_modelBinders, _modelBinders,
_modelValidatorProviders, _modelValidatorProviders,
_valueProviderFactories, _valueProviderFactories,
_actionBindingContextAccessor, _actionBindingContextAccessor,
_logger, _logger,
_telemetry, _telemetry,
_maxModelValidationErrors); _maxModelValidationErrors);
} }
} }
/// <inheritdoc /> /// <inheritdoc />
public void OnProvidersExecuted([NotNull] ActionInvokerProviderContext context) public void OnProvidersExecuted(ActionInvokerProviderContext context)
{ {
} }
} }

View File

@ -40,6 +40,21 @@ namespace Microsoft.AspNet.Mvc.Controllers
ActionBindingContext actionBindingContext, ActionBindingContext actionBindingContext,
object controller) object controller)
{ {
if (actionContext == null)
{
throw new ArgumentNullException(nameof(actionContext));
}
if (actionBindingContext == null)
{
throw new ArgumentNullException(nameof(actionBindingContext));
}
if (controller == null)
{
throw new ArgumentNullException(nameof(controller));
}
var actionDescriptor = actionContext.ActionDescriptor as ControllerActionDescriptor; var actionDescriptor = actionContext.ActionDescriptor as ControllerActionDescriptor;
if (actionDescriptor == null) if (actionDescriptor == null)
{ {
@ -69,10 +84,25 @@ namespace Microsoft.AspNet.Mvc.Controllers
} }
public async Task<ModelBindingResult> BindModelAsync( public async Task<ModelBindingResult> BindModelAsync(
[NotNull] ParameterDescriptor parameter, ParameterDescriptor parameter,
[NotNull] ModelStateDictionary modelState, ModelStateDictionary modelState,
[NotNull] OperationBindingContext operationContext) OperationBindingContext operationContext)
{ {
if (parameter == null)
{
throw new ArgumentNullException(nameof(parameter));
}
if (modelState == null)
{
throw new ArgumentNullException(nameof(modelState));
}
if (operationContext == null)
{
throw new ArgumentNullException(nameof(operationContext));
}
var metadata = _modelMetadataProvider.GetMetadataForType(parameter.ParameterType); var metadata = _modelMetadataProvider.GetMetadataForType(parameter.ParameterType);
var modelBindingContext = ModelBindingContext.CreateBindingContext( var modelBindingContext = ModelBindingContext.CreateBindingContext(
operationContext, operationContext,

View File

@ -3,8 +3,6 @@
using System; using System;
using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Controllers namespace Microsoft.AspNet.Mvc.Controllers
{ {
@ -24,8 +22,18 @@ namespace Microsoft.AspNet.Mvc.Controllers
_typeActivatorCache = typeActivatorCache; _typeActivatorCache = typeActivatorCache;
} }
/// <inheritdoc /> /// <inheritdoc />
public virtual object Create([NotNull] ActionContext actionContext, [NotNull] Type controllerType) public virtual object Create(ActionContext actionContext, Type controllerType)
{ {
if (actionContext == null)
{
throw new ArgumentNullException(nameof(actionContext));
}
if (controllerType == null)
{
throw new ArgumentNullException(nameof(controllerType));
}
var serviceProvider = actionContext.HttpContext.RequestServices; var serviceProvider = actionContext.HttpContext.RequestServices;
return _typeActivatorCache.CreateInstance<object>(serviceProvider, controllerType); return _typeActivatorCache.CreateInstance<object>(serviceProvider, controllerType);
} }

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Controllers namespace Microsoft.AspNet.Mvc.Controllers
{ {
@ -48,8 +47,13 @@ namespace Microsoft.AspNet.Mvc.Controllers
} }
/// <inheritdoc /> /// <inheritdoc />
public virtual object CreateController([NotNull] ActionContext actionContext) public virtual object CreateController(ActionContext actionContext)
{ {
if (actionContext == null)
{
throw new ArgumentNullException(nameof(actionContext));
}
var actionDescriptor = actionContext.ActionDescriptor as ControllerActionDescriptor; var actionDescriptor = actionContext.ActionDescriptor as ControllerActionDescriptor;
if (actionDescriptor == null) if (actionDescriptor == null)
{ {

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Controllers namespace Microsoft.AspNet.Mvc.Controllers
{ {
@ -48,9 +47,19 @@ namespace Microsoft.AspNet.Mvc.Controllers
/// <param name="candidateAssemblies">The set of candidate assemblies.</param> /// <param name="candidateAssemblies">The set of candidate assemblies.</param>
/// <returns><c>true</c> if the <paramref name="typeInfo"/> is a controller. Otherwise <c>false</c>.</returns> /// <returns><c>true</c> if the <paramref name="typeInfo"/> is a controller. Otherwise <c>false</c>.</returns>
protected internal virtual bool IsController( protected internal virtual bool IsController(
[NotNull] TypeInfo typeInfo, TypeInfo typeInfo,
[NotNull] ISet<Assembly> candidateAssemblies) ISet<Assembly> candidateAssemblies)
{ {
if (typeInfo == null)
{
throw new ArgumentNullException(nameof(typeInfo));
}
if (candidateAssemblies == null)
{
throw new ArgumentNullException(nameof(candidateAssemblies));
}
if (!typeInfo.IsClass) if (!typeInfo.IsClass)
{ {
return false; return false;

View File

@ -16,7 +16,6 @@ using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.AspNet.Mvc.Internal; using Microsoft.AspNet.Mvc.Internal;
using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.ModelBinding.Validation; using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.Controllers namespace Microsoft.AspNet.Mvc.Controllers
@ -62,18 +61,68 @@ namespace Microsoft.AspNet.Mvc.Controllers
"Request was short circuited at result filter '{ResultFilter}'."; "Request was short circuited at result filter '{ResultFilter}'.";
public FilterActionInvoker( public FilterActionInvoker(
[NotNull] ActionContext actionContext, ActionContext actionContext,
[NotNull] IReadOnlyList<IFilterProvider> filterProviders, IReadOnlyList<IFilterProvider> filterProviders,
[NotNull] IReadOnlyList<IInputFormatter> inputFormatters, IReadOnlyList<IInputFormatter> inputFormatters,
[NotNull] IReadOnlyList<IOutputFormatter> outputFormatters, IReadOnlyList<IOutputFormatter> outputFormatters,
[NotNull] IReadOnlyList<IModelBinder> modelBinders, IReadOnlyList<IModelBinder> modelBinders,
[NotNull] IReadOnlyList<IModelValidatorProvider> modelValidatorProviders, IReadOnlyList<IModelValidatorProvider> modelValidatorProviders,
[NotNull] IReadOnlyList<IValueProviderFactory> valueProviderFactories, IReadOnlyList<IValueProviderFactory> valueProviderFactories,
[NotNull] IActionBindingContextAccessor actionBindingContextAccessor, IActionBindingContextAccessor actionBindingContextAccessor,
[NotNull] ILogger logger, ILogger logger,
[NotNull] TelemetrySource telemetry, TelemetrySource telemetry,
int maxModelValidationErrors) int maxModelValidationErrors)
{ {
if (actionContext == null)
{
throw new ArgumentNullException(nameof(actionContext));
}
if (filterProviders == null)
{
throw new ArgumentNullException(nameof(filterProviders));
}
if (inputFormatters == null)
{
throw new ArgumentNullException(nameof(inputFormatters));
}
if (outputFormatters == null)
{
throw new ArgumentNullException(nameof(outputFormatters));
}
if (modelBinders == null)
{
throw new ArgumentNullException(nameof(modelBinders));
}
if (modelValidatorProviders == null)
{
throw new ArgumentNullException(nameof(modelValidatorProviders));
}
if (valueProviderFactories == null)
{
throw new ArgumentNullException(nameof(valueProviderFactories));
}
if (actionBindingContextAccessor == null)
{
throw new ArgumentNullException(nameof(actionBindingContextAccessor));
}
if (logger == null)
{
throw new ArgumentNullException(nameof(logger));
}
if (telemetry == null)
{
throw new ArgumentNullException(nameof(telemetry));
}
ActionContext = actionContext; ActionContext = actionContext;
_filterProviders = filterProviders; _filterProviders = filterProviders;
@ -120,8 +169,8 @@ namespace Microsoft.AspNet.Mvc.Controllers
protected abstract Task<IActionResult> InvokeActionAsync(ActionExecutingContext actionExecutingContext); protected abstract Task<IActionResult> InvokeActionAsync(ActionExecutingContext actionExecutingContext);
protected abstract Task<IDictionary<string, object>> BindActionArgumentsAsync( protected abstract Task<IDictionary<string, object>> BindActionArgumentsAsync(
[NotNull] ActionContext context, ActionContext context,
[NotNull] ActionBindingContext bindingContext); ActionBindingContext bindingContext);
public virtual async Task InvokeAsync() public virtual async Task InvokeAsync()
{ {

View File

@ -3,7 +3,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Controllers namespace Microsoft.AspNet.Mvc.Controllers
{ {
@ -21,8 +20,8 @@ namespace Microsoft.AspNet.Mvc.Controllers
/// <param name="bindingContext">The <see cref="ActionBindingContext"/>.</param> /// <param name="bindingContext">The <see cref="ActionBindingContext"/>.</param>
/// <param name="controller">The controller object which contains the action.</param> /// <param name="controller">The controller object which contains the action.</param>
Task<IDictionary<string, object>> BindActionArgumentsAsync( Task<IDictionary<string, object>> BindActionArgumentsAsync(
[NotNull] ActionContext context, ActionContext context,
[NotNull] ActionBindingContext bindingContext, ActionBindingContext bindingContext,
[NotNull] object controller); object controller);
} }
} }

View File

@ -3,7 +3,6 @@
using System; using System;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Controllers namespace Microsoft.AspNet.Mvc.Controllers
{ {
@ -14,8 +13,18 @@ namespace Microsoft.AspNet.Mvc.Controllers
public class ServiceBasedControllerActivator : IControllerActivator public class ServiceBasedControllerActivator : IControllerActivator
{ {
/// <inheritdoc /> /// <inheritdoc />
public object Create([NotNull] ActionContext actionContext, [NotNull] Type controllerType) public object Create(ActionContext actionContext, Type controllerType)
{ {
if (actionContext == null)
{
throw new ArgumentNullException(nameof(actionContext));
}
if (controllerType == null)
{
throw new ArgumentNullException(nameof(controllerType));
}
return actionContext.HttpContext.RequestServices.GetRequiredService(controllerType); return actionContext.HttpContext.RequestServices.GetRequiredService(controllerType);
} }
} }

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Controllers namespace Microsoft.AspNet.Mvc.Controllers
{ {
@ -25,8 +25,13 @@ namespace Microsoft.AspNet.Mvc.Controllers
/// Initializes a new instance of <see cref="StaticControllerTypeProvider"/>. /// Initializes a new instance of <see cref="StaticControllerTypeProvider"/>.
/// </summary> /// </summary>
/// <param name="controllerTypes">The sequence of controller <see cref="TypeInfo"/>.</param> /// <param name="controllerTypes">The sequence of controller <see cref="TypeInfo"/>.</param>
public StaticControllerTypeProvider([NotNull] IEnumerable<TypeInfo> controllerTypes) public StaticControllerTypeProvider(IEnumerable<TypeInfo> controllerTypes)
{ {
if (controllerTypes == null)
{
throw new ArgumentNullException(nameof(controllerTypes));
}
ControllerTypes = new List<TypeInfo>(controllerTypes); ControllerTypes = new List<TypeInfo>(controllerTypes);
} }

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
@ -59,16 +58,21 @@ namespace Microsoft.AspNet.Mvc
public IDictionary<string, object> RouteValues { get; set; } public IDictionary<string, object> RouteValues { get; set; }
/// <inheritdoc /> /// <inheritdoc />
protected override void OnFormatting([NotNull] ActionContext context) protected override void OnFormatting(ActionContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var request = context.HttpContext.Request; var request = context.HttpContext.Request;
var urlHelper = UrlHelper ?? context.HttpContext.RequestServices.GetRequiredService<IUrlHelper>(); var urlHelper = UrlHelper ?? context.HttpContext.RequestServices.GetRequiredService<IUrlHelper>();
var url = urlHelper.Action( var url = urlHelper.Action(
ActionName, ActionName,
ControllerName, ControllerName,
RouteValues, RouteValues,
request.Scheme, request.Scheme,
request.Host.ToUriComponent()); request.Host.ToUriComponent());
if (string.IsNullOrEmpty(url)) if (string.IsNullOrEmpty(url))

View File

@ -5,7 +5,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal; using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
@ -62,8 +61,13 @@ namespace Microsoft.AspNet.Mvc
public IDictionary<string, object> RouteValues { get; set; } public IDictionary<string, object> RouteValues { get; set; }
/// <inheritdoc /> /// <inheritdoc />
protected override void OnFormatting([NotNull] ActionContext context) protected override void OnFormatting(ActionContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var urlHelper = UrlHelper ?? context.HttpContext.RequestServices.GetRequiredService<IUrlHelper>(); var urlHelper = UrlHelper ?? context.HttpContext.RequestServices.GetRequiredService<IUrlHelper>();
var url = urlHelper.Link(RouteName, RouteValues); var url = urlHelper.Link(RouteName, RouteValues);

View File

@ -3,7 +3,6 @@
using System; using System;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
@ -21,9 +20,14 @@ namespace Microsoft.AspNet.Mvc
/// </summary> /// </summary>
/// <param name="location">The location at which the content has been created.</param> /// <param name="location">The location at which the content has been created.</param>
/// <param name="value">The value to format in the entity body.</param> /// <param name="value">The value to format in the entity body.</param>
public CreatedResult([NotNull] string location, object value) public CreatedResult(string location, object value)
: base(value) : base(value)
{ {
if (location == null)
{
throw new ArgumentNullException(nameof(location));
}
Location = location; Location = location;
StatusCode = StatusCodes.Status201Created; StatusCode = StatusCodes.Status201Created;
} }
@ -34,9 +38,14 @@ namespace Microsoft.AspNet.Mvc
/// </summary> /// </summary>
/// <param name="location">The location at which the content has been created.</param> /// <param name="location">The location at which the content has been created.</param>
/// <param name="value">The value to format in the entity body.</param> /// <param name="value">The value to format in the entity body.</param>
public CreatedResult([NotNull] Uri location, object value) public CreatedResult(Uri location, object value)
: base(value) : base(value)
{ {
if (location == null)
{
throw new ArgumentNullException(nameof(location));
}
if (location.IsAbsoluteUri) if (location.IsAbsoluteUri)
{ {
Location = location.AbsoluteUri; Location = location.AbsoluteUri;
@ -70,8 +79,13 @@ namespace Microsoft.AspNet.Mvc
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void OnFormatting([NotNull] ActionContext context) protected override void OnFormatting(ActionContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
context.HttpContext.Response.Headers[HeaderNames.Location] = Location; context.HttpContext.Response.Headers[HeaderNames.Location] = Location;
} }
} }

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Mvc.ApplicationModels; using Microsoft.AspNet.Mvc.ApplicationModels;
using Microsoft.Framework.Internal;
namespace Microsoft.Framework.DependencyInjection namespace Microsoft.Framework.DependencyInjection
{ {
@ -20,9 +20,19 @@ namespace Microsoft.Framework.DependencyInjection
/// <param name="controllerModelConvention">The <see cref="IControllerModelConvention"/> which needs to be /// <param name="controllerModelConvention">The <see cref="IControllerModelConvention"/> which needs to be
/// added.</param> /// added.</param>
public static void Add( public static void Add(
[NotNull] this IList<IApplicationModelConvention> conventions, this IList<IApplicationModelConvention> conventions,
[NotNull] IControllerModelConvention controllerModelConvention) IControllerModelConvention controllerModelConvention)
{ {
if (conventions == null)
{
throw new ArgumentNullException(nameof(conventions));
}
if (controllerModelConvention == null)
{
throw new ArgumentNullException(nameof(controllerModelConvention));
}
conventions.Add(new ControllerApplicationModelConvention(controllerModelConvention)); conventions.Add(new ControllerApplicationModelConvention(controllerModelConvention));
} }
@ -49,14 +59,24 @@ namespace Microsoft.Framework.DependencyInjection
/// </summary> /// </summary>
/// <param name="actionModelConvention">The action convention to be applied on all actions /// <param name="actionModelConvention">The action convention to be applied on all actions
/// in the application.</param> /// in the application.</param>
public ActionApplicationModelConvention([NotNull] IActionModelConvention actionModelConvention) public ActionApplicationModelConvention(IActionModelConvention actionModelConvention)
{ {
if (actionModelConvention == null)
{
throw new ArgumentNullException(nameof(actionModelConvention));
}
_actionModelConvention = actionModelConvention; _actionModelConvention = actionModelConvention;
} }
/// <inheritdoc /> /// <inheritdoc />
public void Apply([NotNull] ApplicationModel application) public void Apply(ApplicationModel application)
{ {
if (application == null)
{
throw new ArgumentNullException(nameof(application));
}
foreach (var controller in application.Controllers) foreach (var controller in application.Controllers)
{ {
foreach (var action in controller.Actions) foreach (var action in controller.Actions)
@ -76,14 +96,24 @@ namespace Microsoft.Framework.DependencyInjection
/// </summary> /// </summary>
/// <param name="controllerConvention">The controller convention to be applied on all controllers /// <param name="controllerConvention">The controller convention to be applied on all controllers
/// in the application.</param> /// in the application.</param>
public ControllerApplicationModelConvention([NotNull] IControllerModelConvention controllerConvention) public ControllerApplicationModelConvention(IControllerModelConvention controllerConvention)
{ {
if (controllerConvention == null)
{
throw new ArgumentNullException(nameof(controllerConvention));
}
_controllerModelConvention = controllerConvention; _controllerModelConvention = controllerConvention;
} }
/// <inheritdoc /> /// <inheritdoc />
public void Apply([NotNull] ApplicationModel application) public void Apply(ApplicationModel application)
{ {
if (application == null)
{
throw new ArgumentNullException(nameof(application));
}
foreach (var controller in application.Controllers) foreach (var controller in application.Controllers)
{ {
_controllerModelConvention.Apply(controller); _controllerModelConvention.Apply(controller);

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
@ -7,7 +7,6 @@ using System.Reflection;
using Microsoft.AspNet.Mvc; using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Formatters; using Microsoft.AspNet.Mvc.Formatters;
using Microsoft.AspNet.Mvc.Internal; using Microsoft.AspNet.Mvc.Internal;
using Microsoft.Framework.Internal;
namespace Microsoft.Framework.DependencyInjection namespace Microsoft.Framework.DependencyInjection
{ {
@ -23,17 +22,37 @@ namespace Microsoft.Framework.DependencyInjection
/// <param name="setupAction">An <see cref="Action{MvcOptions}"/>.</param> /// <param name="setupAction">An <see cref="Action{MvcOptions}"/>.</param>
/// <returns>The <see cref="IMvcBuilder"/>.</returns> /// <returns>The <see cref="IMvcBuilder"/>.</returns>
public static IMvcBuilder AddMvcOptions( public static IMvcBuilder AddMvcOptions(
[NotNull] this IMvcBuilder builder, this IMvcBuilder builder,
[NotNull] Action<MvcOptions> setupAction) Action<MvcOptions> setupAction)
{ {
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (setupAction == null)
{
throw new ArgumentNullException(nameof(setupAction));
}
builder.Services.Configure<MvcOptions>(setupAction); builder.Services.Configure<MvcOptions>(setupAction);
return builder; return builder;
} }
public static IMvcBuilder AddFormatterMappings( public static IMvcBuilder AddFormatterMappings(
[NotNull] this IMvcBuilder builder, this IMvcBuilder builder,
[NotNull] Action<FormatterMappings> setupAction) Action<FormatterMappings> setupAction)
{ {
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (setupAction == null)
{
throw new ArgumentNullException(nameof(setupAction));
}
builder.Services.Configure<MvcOptions>((options) => setupAction(options.FormatterMappings)); builder.Services.Configure<MvcOptions>((options) => setupAction(options.FormatterMappings));
return builder; return builder;
} }
@ -47,9 +66,19 @@ namespace Microsoft.Framework.DependencyInjection
/// <paramref name="services"/> and used for controller discovery.</param> /// <paramref name="services"/> and used for controller discovery.</param>
/// <returns>The <see cref="IMvcBuilder"/>.</returns> /// <returns>The <see cref="IMvcBuilder"/>.</returns>
public static IMvcBuilder AddControllersAsServices( public static IMvcBuilder AddControllersAsServices(
[NotNull] this IMvcBuilder builder, this IMvcBuilder builder,
[NotNull] IEnumerable<Type> controllerTypes) IEnumerable<Type> controllerTypes)
{ {
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (controllerTypes == null)
{
throw new ArgumentNullException(nameof(controllerTypes));
}
ControllersAsServices.AddControllersAsServices(builder.Services, controllerTypes); ControllersAsServices.AddControllersAsServices(builder.Services, controllerTypes);
return builder; return builder;
} }
@ -62,9 +91,19 @@ namespace Microsoft.Framework.DependencyInjection
/// <param name="controllerAssemblies">Assemblies to scan.</param> /// <param name="controllerAssemblies">Assemblies to scan.</param>
/// <returns>The <see cref="IMvcBuilder"/>.</returns> /// <returns>The <see cref="IMvcBuilder"/>.</returns>
public static IMvcBuilder AddControllersAsServices( public static IMvcBuilder AddControllersAsServices(
[NotNull] this IMvcBuilder builder, this IMvcBuilder builder,
[NotNull] IEnumerable<Assembly> controllerAssemblies) IEnumerable<Assembly> controllerAssemblies)
{ {
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (controllerAssemblies == null)
{
throw new ArgumentNullException(nameof(controllerAssemblies));
}
ControllersAsServices.AddControllersAsServices(builder.Services, controllerAssemblies); ControllersAsServices.AddControllersAsServices(builder.Services, controllerAssemblies);
return builder; return builder;
} }

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
@ -10,7 +10,6 @@ using Microsoft.AspNet.Mvc.ApplicationModels;
using Microsoft.AspNet.Mvc.Formatters; using Microsoft.AspNet.Mvc.Formatters;
using Microsoft.AspNet.Mvc.Internal; using Microsoft.AspNet.Mvc.Internal;
using Microsoft.Framework.DependencyInjection.Extensions; using Microsoft.Framework.DependencyInjection.Extensions;
using Microsoft.Framework.Internal;
namespace Microsoft.Framework.DependencyInjection namespace Microsoft.Framework.DependencyInjection
{ {
@ -23,9 +22,19 @@ namespace Microsoft.Framework.DependencyInjection
/// <param name="setupAction">An <see cref="Action{MvcOptions}"/>.</param> /// <param name="setupAction">An <see cref="Action{MvcOptions}"/>.</param>
/// <returns>The <see cref="IMvcCoreBuilder"/>.</returns> /// <returns>The <see cref="IMvcCoreBuilder"/>.</returns>
public static IMvcCoreBuilder AddMvcOptions( public static IMvcCoreBuilder AddMvcOptions(
[NotNull] this IMvcCoreBuilder builder, this IMvcCoreBuilder builder,
[NotNull] Action<MvcOptions> setupAction) Action<MvcOptions> setupAction)
{ {
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (setupAction == null)
{
throw new ArgumentNullException(nameof(setupAction));
}
builder.Services.Configure<MvcOptions>(setupAction); builder.Services.Configure<MvcOptions>(setupAction);
return builder; return builder;
} }
@ -94,9 +103,19 @@ namespace Microsoft.Framework.DependencyInjection
/// <paramref name="services"/> and used for controller discovery.</param> /// <paramref name="services"/> and used for controller discovery.</param>
/// <returns>The <see cref="IMvcCoreBuilder"/>.</returns> /// <returns>The <see cref="IMvcCoreBuilder"/>.</returns>
public static IMvcCoreBuilder AddControllersAsServices( public static IMvcCoreBuilder AddControllersAsServices(
[NotNull] this IMvcCoreBuilder builder, this IMvcCoreBuilder builder,
[NotNull] IEnumerable<Type> controllerTypes) IEnumerable<Type> controllerTypes)
{ {
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (controllerTypes == null)
{
throw new ArgumentNullException(nameof(controllerTypes));
}
ControllersAsServices.AddControllersAsServices(builder.Services, controllerTypes); ControllersAsServices.AddControllersAsServices(builder.Services, controllerTypes);
return builder; return builder;
} }
@ -109,9 +128,19 @@ namespace Microsoft.Framework.DependencyInjection
/// <param name="controllerAssemblies">Assemblies to scan.</param> /// <param name="controllerAssemblies">Assemblies to scan.</param>
/// <returns>The <see cref="IMvcCoreBuilder"/>.</returns> /// <returns>The <see cref="IMvcCoreBuilder"/>.</returns>
public static IMvcCoreBuilder AddControllersAsServices( public static IMvcCoreBuilder AddControllersAsServices(
[NotNull] this IMvcCoreBuilder builder, this IMvcCoreBuilder builder,
[NotNull] IEnumerable<Assembly> controllerAssemblies) IEnumerable<Assembly> controllerAssemblies)
{ {
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
if (controllerAssemblies == null)
{
throw new ArgumentNullException(nameof(controllerAssemblies));
}
ControllersAsServices.AddControllersAsServices(builder.Services, controllerAssemblies); ControllersAsServices.AddControllersAsServices(builder.Services, controllerAssemblies);
return builder; return builder;
} }

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
@ -16,22 +16,31 @@ using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.Routing;
using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection.Extensions; using Microsoft.Framework.DependencyInjection.Extensions;
using Microsoft.Framework.Internal;
using Microsoft.Framework.OptionsModel; using Microsoft.Framework.OptionsModel;
namespace Microsoft.Framework.DependencyInjection namespace Microsoft.Framework.DependencyInjection
{ {
public static class MvcCoreServiceCollectionExtensions public static class MvcCoreServiceCollectionExtensions
{ {
public static IMvcCoreBuilder AddMvcCore([NotNull] this IServiceCollection services) public static IMvcCoreBuilder AddMvcCore(this IServiceCollection services)
{ {
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
return AddMvcCore(services, setupAction: null); return AddMvcCore(services, setupAction: null);
} }
public static IMvcCoreBuilder AddMvcCore( public static IMvcCoreBuilder AddMvcCore(
[NotNull] this IServiceCollection services, this IServiceCollection services,
Action<MvcOptions> setupAction) Action<MvcOptions> setupAction)
{ {
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
ConfigureDefaultServices(services); ConfigureDefaultServices(services);
AddMvcCoreServices(services); AddMvcCoreServices(services);

View File

@ -1,8 +1,6 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
/// <summary> /// <summary>
@ -11,15 +9,8 @@ namespace Microsoft.AspNet.Mvc
/// </summary> /// </summary>
public class EmptyResult : ActionResult public class EmptyResult : ActionResult
{ {
private static readonly EmptyResult _singleton = new EmptyResult();
internal static EmptyResult Instance
{
get { return _singleton; }
}
/// <inheritdoc /> /// <inheritdoc />
public override void ExecuteResult([NotNull] ActionContext context) public override void ExecuteResult(ActionContext context)
{ {
} }
} }

View File

@ -6,7 +6,6 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
@ -26,9 +25,17 @@ namespace Microsoft.AspNet.Mvc
/// </summary> /// </summary>
/// <param name="fileContents">The bytes that represent the file contents.</param> /// <param name="fileContents">The bytes that represent the file contents.</param>
/// <param name="contentType">The Content-Type header of the response.</param> /// <param name="contentType">The Content-Type header of the response.</param>
public FileContentResult([NotNull] byte[] fileContents, [NotNull] string contentType) public FileContentResult(byte[] fileContents, string contentType)
: this(fileContents, new MediaTypeHeaderValue(contentType)) : this(fileContents, new MediaTypeHeaderValue(contentType))
{ {
if (fileContents == null)
{
throw new ArgumentNullException(nameof(fileContents));
}
if (contentType == null)
{
throw new ArgumentNullException(nameof(contentType));
}
} }
/// <summary> /// <summary>
@ -38,9 +45,19 @@ namespace Microsoft.AspNet.Mvc
/// </summary> /// </summary>
/// <param name="fileContents">The bytes that represent the file contents.</param> /// <param name="fileContents">The bytes that represent the file contents.</param>
/// <param name="contentType">The Content-Type header of the response.</param> /// <param name="contentType">The Content-Type header of the response.</param>
public FileContentResult([NotNull] byte[] fileContents, [NotNull] MediaTypeHeaderValue contentType) public FileContentResult(byte[] fileContents, MediaTypeHeaderValue contentType)
: base(contentType) : base(contentType)
{ {
if (fileContents == null)
{
throw new ArgumentNullException(nameof(fileContents));
}
if (contentType == null)
{
throw new ArgumentNullException(nameof(contentType));
}
FileContents = fileContents; FileContents = fileContents;
} }

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
@ -22,9 +22,13 @@ namespace Microsoft.AspNet.Mvc
/// the provided <paramref name="contentType"/>. /// the provided <paramref name="contentType"/>.
/// </summary> /// </summary>
/// <param name="contentType">The Content-Type header of the response.</param> /// <param name="contentType">The Content-Type header of the response.</param>
protected FileResult([NotNull] string contentType) protected FileResult(string contentType)
: this(new MediaTypeHeaderValue(contentType)) : this(new MediaTypeHeaderValue(contentType))
{ {
if (contentType == null)
{
throw new ArgumentNullException(nameof(contentType));
}
} }
/// <summary> /// <summary>
@ -32,8 +36,13 @@ namespace Microsoft.AspNet.Mvc
/// the provided <paramref name="contentType"/>. /// the provided <paramref name="contentType"/>.
/// </summary> /// </summary>
/// <param name="contentType">The Content-Type header of the response.</param> /// <param name="contentType">The Content-Type header of the response.</param>
protected FileResult([NotNull] MediaTypeHeaderValue contentType) protected FileResult(MediaTypeHeaderValue contentType)
{ {
if (contentType == null)
{
throw new ArgumentNullException(nameof(contentType));
}
ContentType = contentType; ContentType = contentType;
} }
@ -52,8 +61,13 @@ namespace Microsoft.AspNet.Mvc
} }
/// <inheritdoc /> /// <inheritdoc />
public override Task ExecuteResultAsync([NotNull] ActionContext context) public override Task ExecuteResultAsync(ActionContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var response = context.HttpContext.Response; var response = context.HttpContext.Response;
response.ContentType = ContentType.ToString(); response.ContentType = ContentType.ToString();

View File

@ -7,7 +7,6 @@ using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
@ -30,7 +29,7 @@ namespace Microsoft.AspNet.Mvc
/// </summary> /// </summary>
/// <param name="fileStream">The stream with the file.</param> /// <param name="fileStream">The stream with the file.</param>
/// <param name="contentType">The Content-Type header of the response.</param> /// <param name="contentType">The Content-Type header of the response.</param>
public FileStreamResult([NotNull] Stream fileStream, [NotNull] string contentType) public FileStreamResult(Stream fileStream, string contentType)
: this(fileStream, new MediaTypeHeaderValue(contentType)) : this(fileStream, new MediaTypeHeaderValue(contentType))
{ {
} }
@ -42,9 +41,19 @@ namespace Microsoft.AspNet.Mvc
/// </summary> /// </summary>
/// <param name="fileStream">The stream with the file.</param> /// <param name="fileStream">The stream with the file.</param>
/// <param name="contentType">The Content-Type header of the response.</param> /// <param name="contentType">The Content-Type header of the response.</param>
public FileStreamResult([NotNull] Stream fileStream, [NotNull] MediaTypeHeaderValue contentType) public FileStreamResult(Stream fileStream, MediaTypeHeaderValue contentType)
: base(contentType) : base(contentType)
{ {
if (fileStream == null)
{
throw new ArgumentNullException(nameof(fileStream));
}
if (contentType == null)
{
throw new ArgumentNullException(nameof(contentType));
}
FileStream = fileStream; FileStream = fileStream;
} }

View File

@ -3,7 +3,6 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
@ -13,18 +12,28 @@ namespace Microsoft.AspNet.Mvc.Filters
{ {
public int Order { get; set; } public int Order { get; set; }
public virtual void OnActionExecuting([NotNull] ActionExecutingContext context) public virtual void OnActionExecuting(ActionExecutingContext context)
{ {
} }
public virtual void OnActionExecuted([NotNull] ActionExecutedContext context) public virtual void OnActionExecuted(ActionExecutedContext context)
{ {
} }
public virtual async Task OnActionExecutionAsync( public virtual async Task OnActionExecutionAsync(
[NotNull] ActionExecutingContext context, ActionExecutingContext context,
[NotNull] ActionExecutionDelegate next) ActionExecutionDelegate next)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (next == null)
{
throw new ArgumentNullException(nameof(next));
}
OnActionExecuting(context); OnActionExecuting(context);
if (context.Result == null) if (context.Result == null)
{ {
@ -32,18 +41,28 @@ namespace Microsoft.AspNet.Mvc.Filters
} }
} }
public virtual void OnResultExecuting([NotNull] ResultExecutingContext context) public virtual void OnResultExecuting(ResultExecutingContext context)
{ {
} }
public virtual void OnResultExecuted([NotNull] ResultExecutedContext context) public virtual void OnResultExecuted(ResultExecutedContext context)
{ {
} }
public virtual async Task OnResultExecutionAsync( public virtual async Task OnResultExecutionAsync(
[NotNull] ResultExecutingContext context, ResultExecutingContext context,
[NotNull] ResultExecutionDelegate next) ResultExecutionDelegate next)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (next == null)
{
throw new ArgumentNullException(nameof(next));
}
OnResultExecuting(context); OnResultExecuting(context);
if (!context.Cancel) if (!context.Cancel)
{ {

View File

@ -5,7 +5,6 @@ using System;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Internal; using Microsoft.AspNet.Mvc.Internal;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
@ -15,23 +14,38 @@ namespace Microsoft.AspNet.Mvc.Filters
{ {
public int Order { get; set; } public int Order { get; set; }
public virtual Task OnAuthorizationAsync([NotNull] AuthorizationContext context) public virtual Task OnAuthorizationAsync(AuthorizationContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
OnAuthorization(context); OnAuthorization(context);
return TaskCache.CompletedTask; return TaskCache.CompletedTask;
} }
public virtual void OnAuthorization([NotNull] AuthorizationContext context) public virtual void OnAuthorization(AuthorizationContext context)
{ {
} }
protected virtual bool HasAllowAnonymous([NotNull] AuthorizationContext context) protected virtual bool HasAllowAnonymous(AuthorizationContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
return context.Filters.Any(item => item is IAllowAnonymous); return context.Filters.Any(item => item is IAllowAnonymous);
} }
protected virtual void Fail([NotNull] AuthorizationContext context) protected virtual void Fail(AuthorizationContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
context.Result = new HttpUnauthorizedResult(); context.Result = new HttpUnauthorizedResult();
} }
} }

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -19,8 +20,13 @@ namespace Microsoft.AspNet.Mvc.Filters
/// Authorize filter for a specific policy. /// Authorize filter for a specific policy.
/// </summary> /// </summary>
/// <param name="policy">Authorization policy to be used.</param> /// <param name="policy">Authorization policy to be used.</param>
public AuthorizeFilter([NotNull] AuthorizationPolicy policy) public AuthorizeFilter(AuthorizationPolicy policy)
{ {
if (policy == null)
{
throw new ArgumentNullException(nameof(policy));
}
Policy = policy; Policy = policy;
} }
@ -30,8 +36,13 @@ namespace Microsoft.AspNet.Mvc.Filters
public AuthorizationPolicy Policy { get; private set; } public AuthorizationPolicy Policy { get; private set; }
/// <inheritdoc /> /// <inheritdoc />
public virtual async Task OnAuthorizationAsync([NotNull] Filters.AuthorizationContext context) public virtual async Task OnAuthorizationAsync(Filters.AuthorizationContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
// Build a ClaimsPrincipal with the Policy's required authentication types // Build a ClaimsPrincipal with the Policy's required authentication types
if (Policy.ActiveAuthenticationSchemes != null && Policy.ActiveAuthenticationSchemes.Any()) if (Policy.ActiveAuthenticationSchemes != null && Policy.ActiveAuthenticationSchemes.Any())
{ {

View File

@ -4,7 +4,6 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
@ -19,9 +18,19 @@ namespace Microsoft.AspNet.Mvc.Filters
/// <inheritdoc /> /// <inheritdoc />
public async Task OnActionExecutionAsync( public async Task OnActionExecutionAsync(
[NotNull] ActionExecutingContext context, ActionExecutingContext context,
[NotNull] ActionExecutionDelegate next) ActionExecutionDelegate next)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (next == null)
{
throw new ArgumentNullException(nameof(next));
}
var controller = context.Controller; var controller = context.Controller;
if (controller == null) if (controller == null)
{ {

View File

@ -4,7 +4,6 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
@ -19,9 +18,19 @@ namespace Microsoft.AspNet.Mvc.Filters
/// <inheritdoc /> /// <inheritdoc />
public async Task OnResultExecutionAsync( public async Task OnResultExecutionAsync(
[NotNull] ResultExecutingContext context, ResultExecutingContext context,
[NotNull] ResultExecutionDelegate next) ResultExecutionDelegate next)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (next == null)
{
throw new ArgumentNullException(nameof(next));
}
var controller = context.Controller; var controller = context.Controller;
if (controller == null) if (controller == null)
{ {

View File

@ -4,7 +4,6 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
@ -16,8 +15,13 @@ namespace Microsoft.AspNet.Mvc.Filters
} }
/// <inheritdoc /> /// <inheritdoc />
public void OnProvidersExecuting([NotNull] FilterProviderContext context) public void OnProvidersExecuting(FilterProviderContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (context.ActionContext.ActionDescriptor.FilterDescriptors != null) if (context.ActionContext.ActionDescriptor.FilterDescriptors != null)
{ {
// Perf: Avoid allocations // Perf: Avoid allocations
@ -29,7 +33,7 @@ namespace Microsoft.AspNet.Mvc.Filters
} }
/// <inheritdoc /> /// <inheritdoc />
public void OnProvidersExecuted([NotNull] FilterProviderContext context) public void OnProvidersExecuted(FilterProviderContext context)
{ {
} }

View File

@ -4,7 +4,6 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Internal; using Microsoft.AspNet.Mvc.Internal;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
@ -13,13 +12,18 @@ namespace Microsoft.AspNet.Mvc.Filters
{ {
public int Order { get; set; } public int Order { get; set; }
public virtual Task OnExceptionAsync([NotNull] ExceptionContext context) public virtual Task OnExceptionAsync(ExceptionContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
OnException(context); OnException(context);
return TaskCache.CompletedTask; return TaskCache.CompletedTask;
} }
public virtual void OnException([NotNull] ExceptionContext context) public virtual void OnException(ExceptionContext context)
{ {
} }
} }

View File

@ -1,11 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Reflection; using System.Reflection;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
@ -21,8 +20,13 @@ namespace Microsoft.AspNet.Mvc.Filters
/// <see cref="Microsoft.Framework.DependencyInjection.ActivatorUtilities"/>. /// <see cref="Microsoft.Framework.DependencyInjection.ActivatorUtilities"/>.
/// Use <see cref="AddService(Type)"/> to register a service as a filter. /// Use <see cref="AddService(Type)"/> to register a service as a filter.
/// </remarks> /// </remarks>
public IFilterMetadata Add([NotNull] Type filterType) public IFilterMetadata Add(Type filterType)
{ {
if (filterType == null)
{
throw new ArgumentNullException(nameof(filterType));
}
return Add(filterType, order: 0); return Add(filterType, order: 0);
} }
@ -37,8 +41,13 @@ namespace Microsoft.AspNet.Mvc.Filters
/// <see cref="Microsoft.Framework.DependencyInjection.ActivatorUtilities"/>. /// <see cref="Microsoft.Framework.DependencyInjection.ActivatorUtilities"/>.
/// Use <see cref="AddService(Type)"/> to register a service as a filter. /// Use <see cref="AddService(Type)"/> to register a service as a filter.
/// </remarks> /// </remarks>
public IFilterMetadata Add([NotNull] Type filterType, int order) public IFilterMetadata Add(Type filterType, int order)
{ {
if (filterType == null)
{
throw new ArgumentNullException(nameof(filterType));
}
if (!typeof(IFilterMetadata).IsAssignableFrom(filterType)) if (!typeof(IFilterMetadata).IsAssignableFrom(filterType))
{ {
var message = Resources.FormatTypeMustDeriveFromType( var message = Resources.FormatTypeMustDeriveFromType(
@ -62,8 +71,13 @@ namespace Microsoft.AspNet.Mvc.Filters
/// <see cref="Add(Type)"/> to register a service that will be created via /// <see cref="Add(Type)"/> to register a service that will be created via
/// type activation. /// type activation.
/// </remarks> /// </remarks>
public IFilterMetadata AddService([NotNull] Type filterType) public IFilterMetadata AddService(Type filterType)
{ {
if (filterType == null)
{
throw new ArgumentNullException(nameof(filterType));
}
return AddService(filterType, order: 0); return AddService(filterType, order: 0);
} }
@ -78,8 +92,13 @@ namespace Microsoft.AspNet.Mvc.Filters
/// <see cref="Add(Type)"/> to register a service that will be created via /// <see cref="Add(Type)"/> to register a service that will be created via
/// type activation. /// type activation.
/// </remarks> /// </remarks>
public IFilterMetadata AddService([NotNull] Type filterType, int order) public IFilterMetadata AddService(Type filterType, int order)
{ {
if (filterType == null)
{
throw new ArgumentNullException(nameof(filterType));
}
if (!typeof(IFilterMetadata).GetTypeInfo().IsAssignableFrom(filterType.GetTypeInfo())) if (!typeof(IFilterMetadata).GetTypeInfo().IsAssignableFrom(filterType.GetTypeInfo()))
{ {
var message = Resources.FormatTypeMustDeriveFromType( var message = Resources.FormatTypeMustDeriveFromType(

View File

@ -1,8 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
@ -15,8 +15,18 @@ namespace Microsoft.AspNet.Mvc.Filters
get { return _comparer; } get { return _comparer; }
} }
public int Compare([NotNull]FilterDescriptor x, [NotNull]FilterDescriptor y) public int Compare(FilterDescriptor x, FilterDescriptor y)
{ {
if (x == null)
{
throw new ArgumentNullException(nameof(x));
}
if (y == null)
{
throw new ArgumentNullException(nameof(y));
}
if (x.Order == y.Order) if (x.Order == y.Order)
{ {
return x.Scope.CompareTo(y.Scope); return x.Scope.CompareTo(y.Scope);

View File

@ -1,8 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
@ -15,8 +15,18 @@ namespace Microsoft.AspNet.Mvc.Filters
get { return _comparer; } get { return _comparer; }
} }
public int Compare([NotNull] FilterItem x, [NotNull] FilterItem y) public int Compare(FilterItem x, FilterItem y)
{ {
if (x == null)
{
throw new ArgumentNullException(nameof(x));
}
if (y == null)
{
throw new ArgumentNullException(nameof(y));
}
return FilterDescriptorOrderComparer.Comparer.Compare(x.Descriptor, y.Descriptor); return FilterDescriptorOrderComparer.Comparer.Compare(x.Descriptor, y.Descriptor);
} }
} }

View File

@ -6,7 +6,6 @@ using System.Globalization;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
@ -74,8 +73,13 @@ namespace Microsoft.AspNet.Mvc.Filters
} }
// <inheritdoc /> // <inheritdoc />
public void OnActionExecuting([NotNull] ActionExecutingContext context) public void OnActionExecuting(ActionExecutingContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
// If there are more filters which can override the values written by this filter, // If there are more filters which can override the values written by this filter,
// then skip execution of this filter. // then skip execution of this filter.
if (IsOverridden(context)) if (IsOverridden(context))
@ -137,7 +141,7 @@ namespace Microsoft.AspNet.Mvc.Filters
CultureInfo.InvariantCulture, CultureInfo.InvariantCulture,
"{0}{1}max-age={2}", "{0}{1}max-age={2}",
cacheControlValue, cacheControlValue,
cacheControlValue != null? "," : null, cacheControlValue != null ? "," : null,
Duration); Duration);
if (cacheControlValue != null) if (cacheControlValue != null)
@ -148,13 +152,18 @@ namespace Microsoft.AspNet.Mvc.Filters
} }
// <inheritdoc /> // <inheritdoc />
public void OnActionExecuted([NotNull]ActionExecutedContext context) public void OnActionExecuted(ActionExecutedContext context)
{ {
} }
// internal for Unit Testing purposes. // internal for Unit Testing purposes.
internal bool IsOverridden([NotNull] ActionExecutingContext context) internal bool IsOverridden(ActionExecutingContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
// Return true if there are any filters which are after the current filter. In which case the current // Return true if there are any filters which are after the current filter. In which case the current
// filter should be skipped. // filter should be skipped.
return context.Filters.OfType<IResponseCacheFilter>().Last() != this; return context.Filters.OfType<IResponseCacheFilter>().Last() != this;

View File

@ -3,7 +3,6 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Filters namespace Microsoft.AspNet.Mvc.Filters
{ {
@ -12,18 +11,28 @@ namespace Microsoft.AspNet.Mvc.Filters
{ {
public int Order { get; set; } public int Order { get; set; }
public virtual void OnResultExecuting([NotNull] ResultExecutingContext context) public virtual void OnResultExecuting(ResultExecutingContext context)
{ {
} }
public virtual void OnResultExecuted([NotNull] ResultExecutedContext context) public virtual void OnResultExecuted(ResultExecutedContext context)
{ {
} }
public virtual async Task OnResultExecutionAsync( public virtual async Task OnResultExecutionAsync(
[NotNull] ResultExecutingContext context, ResultExecutingContext context,
[NotNull] ResultExecutionDelegate next) ResultExecutionDelegate next)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (next == null)
{
throw new ArgumentNullException(nameof(next));
}
OnResultExecuting(context); OnResultExecuting(context);
if (!context.Cancel) if (!context.Cancel)
{ {

View File

@ -5,7 +5,6 @@ using System;
using Microsoft.AspNet.Mvc.Filters; using Microsoft.AspNet.Mvc.Filters;
using Microsoft.AspNet.Mvc.Formatters; using Microsoft.AspNet.Mvc.Formatters;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -21,8 +20,13 @@ namespace Microsoft.AspNet.Mvc
/// </summary> /// </summary>
/// <param name="serviceProvider">The <see cref="IServiceProvider"/>.</param> /// <param name="serviceProvider">The <see cref="IServiceProvider"/>.</param>
/// <returns>An instance of <see cref="FormatFilter"/>.</returns> /// <returns>An instance of <see cref="FormatFilter"/>.</returns>
public IFilterMetadata CreateInstance([NotNull] IServiceProvider serviceProvider) public IFilterMetadata CreateInstance(IServiceProvider serviceProvider)
{ {
if (serviceProvider == null)
{
throw new ArgumentNullException(nameof(serviceProvider));
}
return serviceProvider.GetRequiredService<FormatFilter>(); return serviceProvider.GetRequiredService<FormatFilter>();
} }
} }

View File

@ -1,12 +1,12 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using Microsoft.AspNet.Mvc.ApiExplorer; using Microsoft.AspNet.Mvc.ApiExplorer;
using Microsoft.AspNet.Mvc.Filters; using Microsoft.AspNet.Mvc.Filters;
using Microsoft.AspNet.Mvc.Infrastructure; using Microsoft.AspNet.Mvc.Infrastructure;
using Microsoft.Framework.Internal;
using Microsoft.Framework.OptionsModel; using Microsoft.Framework.OptionsModel;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
@ -58,8 +58,13 @@ namespace Microsoft.AspNet.Mvc.Formatters
/// 2. If there is a conflicting producesFilter. /// 2. If there is a conflicting producesFilter.
/// </summary> /// </summary>
/// <param name="context">The <see cref="ResourceExecutingContext"/>.</param> /// <param name="context">The <see cref="ResourceExecutingContext"/>.</param>
public void OnResourceExecuting([NotNull] ResourceExecutingContext context) public void OnResourceExecuting(ResourceExecutingContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (!IsActive) if (!IsActive)
{ {
return; // no format specified by user, so the filter is muted return; // no format specified by user, so the filter is muted
@ -92,7 +97,7 @@ namespace Microsoft.AspNet.Mvc.Formatters
} }
/// <inheritdoc /> /// <inheritdoc />
public void OnResourceExecuted([NotNull] ResourceExecutedContext context) public void OnResourceExecuted(ResourceExecutedContext context)
{ {
} }
@ -100,8 +105,13 @@ namespace Microsoft.AspNet.Mvc.Formatters
/// Sets a Content Type on an <see cref="ObjectResult" /> using a format value from the request. /// Sets a Content Type on an <see cref="ObjectResult" /> using a format value from the request.
/// </summary> /// </summary>
/// <param name="context">The <see cref="ResultExecutingContext"/>.</param> /// <param name="context">The <see cref="ResultExecutingContext"/>.</param>
public void OnResultExecuting([NotNull] ResultExecutingContext context) public void OnResultExecuting(ResultExecutingContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (!IsActive) if (!IsActive)
{ {
return; // no format specified by user, so the filter is muted return; // no format specified by user, so the filter is muted
@ -116,8 +126,12 @@ namespace Microsoft.AspNet.Mvc.Formatters
} }
/// <inheritdoc /> /// <inheritdoc />
public void OnResultExecuted([NotNull] ResultExecutedContext context) public void OnResultExecuted(ResultExecutedContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
} }
private string GetFormat(ActionContext context) private string GetFormat(ActionContext context)

View File

@ -4,7 +4,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc.Formatters namespace Microsoft.AspNet.Mvc.Formatters
@ -23,8 +22,18 @@ namespace Microsoft.AspNet.Mvc.Formatters
/// </summary> /// </summary>
/// <param name="format">The format value.</param> /// <param name="format">The format value.</param>
/// <param name="contentType">The <see cref="MediaTypeHeaderValue"/> for the format value.</param> /// <param name="contentType">The <see cref="MediaTypeHeaderValue"/> for the format value.</param>
public void SetMediaTypeMappingForFormat([NotNull] string format, [NotNull] MediaTypeHeaderValue contentType) public void SetMediaTypeMappingForFormat(string format, MediaTypeHeaderValue contentType)
{ {
if (format == null)
{
throw new ArgumentNullException(nameof(format));
}
if (contentType == null)
{
throw new ArgumentNullException(nameof(contentType));
}
ValidateContentType(contentType); ValidateContentType(contentType);
format = RemovePeriodIfPresent(format); format = RemovePeriodIfPresent(format);
_map[format] = contentType.CopyAsReadOnly(); _map[format] = contentType.CopyAsReadOnly();
@ -35,8 +44,13 @@ namespace Microsoft.AspNet.Mvc.Formatters
/// </summary> /// </summary>
/// <param name="format">The format value.</param> /// <param name="format">The format value.</param>
/// <returns>The <see cref="MediaTypeHeaderValue"/> for input format.</returns> /// <returns>The <see cref="MediaTypeHeaderValue"/> for input format.</returns>
public MediaTypeHeaderValue GetMediaTypeMappingForFormat([NotNull] string format) public MediaTypeHeaderValue GetMediaTypeMappingForFormat(string format)
{ {
if (format == null)
{
throw new ArgumentNullException(nameof(format));
}
format = RemovePeriodIfPresent(format); format = RemovePeriodIfPresent(format);
MediaTypeHeaderValue value = null; MediaTypeHeaderValue value = null;
@ -50,8 +64,13 @@ namespace Microsoft.AspNet.Mvc.Formatters
/// </summary> /// </summary>
/// <param name="format">The format value.</param> /// <param name="format">The format value.</param>
/// <returns><c>true</c> if the format is successfully found and cleared; otherwise, <c>false</c>.</returns> /// <returns><c>true</c> if the format is successfully found and cleared; otherwise, <c>false</c>.</returns>
public bool ClearMediaTypeMappingForFormat([NotNull] string format) public bool ClearMediaTypeMappingForFormat(string format)
{ {
if (format == null)
{
throw new ArgumentNullException(nameof(format));
}
format = RemovePeriodIfPresent(format); format = RemovePeriodIfPresent(format);
return _map.Remove(format); return _map.Remove(format);
} }

View File

@ -9,7 +9,6 @@ using System.Threading.Tasks;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.ApiExplorer; using Microsoft.AspNet.Mvc.ApiExplorer;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc.Formatters namespace Microsoft.AspNet.Mvc.Formatters
@ -102,8 +101,13 @@ namespace Microsoft.AspNet.Mvc.Formatters
/// <param name="context">The formatter context associated with the call. /// <param name="context">The formatter context associated with the call.
/// </param> /// </param>
/// <returns>The <see cref="Encoding"/> to use when reading the request or writing the response.</returns> /// <returns>The <see cref="Encoding"/> to use when reading the request or writing the response.</returns>
public virtual Encoding SelectCharacterEncoding([NotNull] OutputFormatterContext context) public virtual Encoding SelectCharacterEncoding(OutputFormatterContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var request = context.HttpContext.Request; var request = context.HttpContext.Request;
var encoding = MatchAcceptCharacterEncoding(request.GetTypedHeaders().AcceptCharset); var encoding = MatchAcceptCharacterEncoding(request.GetTypedHeaders().AcceptCharset);
if (encoding == null) if (encoding == null)
@ -125,8 +129,13 @@ namespace Microsoft.AspNet.Mvc.Formatters
} }
/// <inheritdoc /> /// <inheritdoc />
public virtual bool CanWriteResult([NotNull] OutputFormatterContext context, MediaTypeHeaderValue contentType) public virtual bool CanWriteResult(OutputFormatterContext context, MediaTypeHeaderValue contentType)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var runtimeType = context.Object == null ? null : context.Object.GetType(); var runtimeType = context.Object == null ? null : context.Object.GetType();
if (!CanWriteType(context.DeclaredType, runtimeType)) if (!CanWriteType(context.DeclaredType, runtimeType))
{ {
@ -158,8 +167,13 @@ namespace Microsoft.AspNet.Mvc.Formatters
} }
/// <inheritdoc /> /// <inheritdoc />
public Task WriteAsync([NotNull] OutputFormatterContext context) public Task WriteAsync(OutputFormatterContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
WriteResponseHeaders(context); WriteResponseHeaders(context);
return WriteResponseBodyAsync(context); return WriteResponseBodyAsync(context);
} }
@ -168,8 +182,13 @@ namespace Microsoft.AspNet.Mvc.Formatters
/// Sets the headers on <see cref="Microsoft.AspNet.Http.HttpResponse"/> object. /// Sets the headers on <see cref="Microsoft.AspNet.Http.HttpResponse"/> object.
/// </summary> /// </summary>
/// <param name="context">The formatter context associated with the call.</param> /// <param name="context">The formatter context associated with the call.</param>
public virtual void WriteResponseHeaders([NotNull] OutputFormatterContext context) public virtual void WriteResponseHeaders(OutputFormatterContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var selectedMediaType = context.SelectedContentType; var selectedMediaType = context.SelectedContentType;
// If content type is not set then set it based on supported media types. // If content type is not set then set it based on supported media types.
@ -211,7 +230,7 @@ namespace Microsoft.AspNet.Mvc.Formatters
/// </summary> /// </summary>
/// <param name="context">The formatter context associated with the call.</param> /// <param name="context">The formatter context associated with the call.</param>
/// <returns>A task which can write the response body.</returns> /// <returns>A task which can write the response body.</returns>
public abstract Task WriteResponseBodyAsync([NotNull] OutputFormatterContext context); public abstract Task WriteResponseBodyAsync(OutputFormatterContext context);
private Encoding MatchAcceptCharacterEncoding(IList<StringWithQualityHeaderValue> acceptCharsetHeaders) private Encoding MatchAcceptCharacterEncoding(IList<StringWithQualityHeaderValue> acceptCharsetHeaders)
{ {

View File

@ -1,10 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.IO; using System.IO;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http.Features; using Microsoft.AspNet.Http.Features;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc.Formatters namespace Microsoft.AspNet.Mvc.Formatters
@ -15,8 +15,13 @@ namespace Microsoft.AspNet.Mvc.Formatters
public class StreamOutputFormatter : IOutputFormatter public class StreamOutputFormatter : IOutputFormatter
{ {
/// <inheritdoc /> /// <inheritdoc />
public bool CanWriteResult([NotNull] OutputFormatterContext context, MediaTypeHeaderValue contentType) public bool CanWriteResult(OutputFormatterContext context, MediaTypeHeaderValue contentType)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
// Ignore the passed in content type, if the object is a Stream. // Ignore the passed in content type, if the object is a Stream.
if (context.Object is Stream) if (context.Object is Stream)
{ {
@ -28,8 +33,13 @@ namespace Microsoft.AspNet.Mvc.Formatters
} }
/// <inheritdoc /> /// <inheritdoc />
public async Task WriteAsync([NotNull] OutputFormatterContext context) public async Task WriteAsync(OutputFormatterContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
using (var valueAsStream = ((Stream)context.Object)) using (var valueAsStream = ((Stream)context.Object))
{ {
var response = context.HttpContext.Response; var response = context.HttpContext.Response;

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
@ -23,6 +24,11 @@ namespace Microsoft.AspNet.Mvc.Formatters
public override bool CanWriteResult(OutputFormatterContext context, MediaTypeHeaderValue contentType) public override bool CanWriteResult(OutputFormatterContext context, MediaTypeHeaderValue contentType)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
// Ignore the passed in content type, if the object is string // Ignore the passed in content type, if the object is string
// always return it as a text/plain format. // always return it as a text/plain format.
if (context.DeclaredType == typeof(string)) if (context.DeclaredType == typeof(string))
@ -40,6 +46,11 @@ namespace Microsoft.AspNet.Mvc.Formatters
public override Task WriteResponseBodyAsync(OutputFormatterContext context) public override Task WriteResponseBodyAsync(OutputFormatterContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var valueAsString = (string)context.Object; var valueAsString = (string)context.Object;
if (string.IsNullOrEmpty(valueAsString)) if (string.IsNullOrEmpty(valueAsString))
{ {

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -26,9 +26,13 @@ namespace Microsoft.AspNet.Mvc
/// Creates a new <see cref="HttpDeleteAttribute"/> with the given route template. /// Creates a new <see cref="HttpDeleteAttribute"/> with the given route template.
/// </summary> /// </summary>
/// <param name="template">The route template. May not be null.</param> /// <param name="template">The route template. May not be null.</param>
public HttpDeleteAttribute([NotNull] string template) public HttpDeleteAttribute(string template)
: base(_supportedMethods, template) : base(_supportedMethods, template)
{ {
if (template == null)
{
throw new ArgumentNullException(nameof(template));
}
} }
} }
} }

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -26,9 +26,13 @@ namespace Microsoft.AspNet.Mvc
/// Creates a new <see cref="HttpGetAttribute"/> with the given route template. /// Creates a new <see cref="HttpGetAttribute"/> with the given route template.
/// </summary> /// </summary>
/// <param name="template">The route template. May not be null.</param> /// <param name="template">The route template. May not be null.</param>
public HttpGetAttribute([NotNull] string template) public HttpGetAttribute(string template)
: base(_supportedMethods, template) : base(_supportedMethods, template)
{ {
if (template == null)
{
throw new ArgumentNullException(nameof(template));
}
} }
} }
} }

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -26,9 +26,13 @@ namespace Microsoft.AspNet.Mvc
/// Creates a new <see cref="HttpHeadAttribute"/> with the given route template. /// Creates a new <see cref="HttpHeadAttribute"/> with the given route template.
/// </summary> /// </summary>
/// <param name="template">The route template. May not be null.</param> /// <param name="template">The route template. May not be null.</param>
public HttpHeadAttribute([NotNull] string template) public HttpHeadAttribute(string template)
: base(_supportedMethods, template) : base(_supportedMethods, template)
{ {
if (template == null)
{
throw new ArgumentNullException(nameof(template));
}
} }
} }
} }

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -26,9 +26,13 @@ namespace Microsoft.AspNet.Mvc
/// Creates a new <see cref="HttpPatchAttribute"/> with the given route template. /// Creates a new <see cref="HttpPatchAttribute"/> with the given route template.
/// </summary> /// </summary>
/// <param name="template">The route template. May not be null.</param> /// <param name="template">The route template. May not be null.</param>
public HttpPatchAttribute([NotNull] string template) public HttpPatchAttribute(string template)
: base(_supportedMethods, template) : base(_supportedMethods, template)
{ {
if (template == null)
{
throw new ArgumentNullException(nameof(template));
}
} }
} }
} }

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -26,9 +26,13 @@ namespace Microsoft.AspNet.Mvc
/// Creates a new <see cref="HttpPostAttribute"/> with the given route template. /// Creates a new <see cref="HttpPostAttribute"/> with the given route template.
/// </summary> /// </summary>
/// <param name="template">The route template. May not be null.</param> /// <param name="template">The route template. May not be null.</param>
public HttpPostAttribute([NotNull] string template) public HttpPostAttribute(string template)
: base(_supportedMethods, template) : base(_supportedMethods, template)
{ {
if (template == null)
{
throw new ArgumentNullException(nameof(template));
}
} }
} }
} }

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -26,9 +26,13 @@ namespace Microsoft.AspNet.Mvc
/// Creates a new <see cref="HttpPutAttribute"/> with the given route template. /// Creates a new <see cref="HttpPutAttribute"/> with the given route template.
/// </summary> /// </summary>
/// <param name="template">The route template. May not be null.</param> /// <param name="template">The route template. May not be null.</param>
public HttpPutAttribute([NotNull] string template) public HttpPutAttribute(string template)
: base(_supportedMethods, template) : base(_supportedMethods, template)
{ {
if (template == null)
{
throw new ArgumentNullException(nameof(template));
}
} }
} }
} }

View File

@ -1,11 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.IO; using System.IO;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -31,8 +30,18 @@ namespace Microsoft.AspNet.Mvc
{ {
} }
public HttpResponseStreamWriter([NotNull] Stream stream, [NotNull] Encoding encoding, int bufferSize) public HttpResponseStreamWriter(Stream stream, Encoding encoding, int bufferSize)
{ {
if (stream == null)
{
throw new ArgumentNullException(nameof(stream));
}
if (encoding == null)
{
throw new ArgumentNullException(nameof(encoding));
}
_stream = stream; _stream = stream;
Encoding = encoding; Encoding = encoding;
_encoder = encoding.GetEncoder(); _encoder = encoding.GetEncoder();

View File

@ -1,7 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Framework.Internal; using System;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -27,8 +27,13 @@ namespace Microsoft.AspNet.Mvc
public int StatusCode { get; private set; } public int StatusCode { get; private set; }
/// <inheritdoc /> /// <inheritdoc />
public override void ExecuteResult([NotNull] ActionContext context) public override void ExecuteResult(ActionContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
context.HttpContext.Response.StatusCode = StatusCode; context.HttpContext.Response.StatusCode = StatusCode;
} }
} }

View File

@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc namespace Microsoft.AspNet.Mvc
{ {
@ -17,7 +16,7 @@ namespace Microsoft.AspNet.Mvc
/// </summary> /// </summary>
/// <param name="actionContext">The context object for the generated URLs for an action method.</param> /// <param name="actionContext">The context object for the generated URLs for an action method.</param>
/// <returns>The fully qualified or absolute URL to an action method.</returns> /// <returns>The fully qualified or absolute URL to an action method.</returns>
string Action([NotNull] UrlActionContext actionContext); string Action(UrlActionContext actionContext);
/// <summary> /// <summary>
/// Converts a virtual (relative) path to an application absolute path. /// Converts a virtual (relative) path to an application absolute path.
@ -57,7 +56,7 @@ namespace Microsoft.AspNet.Mvc
/// </summary> /// </summary>
/// <param name="routeContext">The context object for the generated URLs for a route.</param> /// <param name="routeContext">The context object for the generated URLs for a route.</param>
/// <returns>The fully qualified or absolute URL.</returns> /// <returns>The fully qualified or absolute URL.</returns>
string RouteUrl([NotNull] UrlRouteContext routeContext); string RouteUrl(UrlRouteContext routeContext);
/// <summary> /// <summary>
/// Generates an absolute URL using the specified route name and values. /// Generates an absolute URL using the specified route name and values.

View File

@ -1,9 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Microsoft.AspNet.Mvc.Abstractions; using Microsoft.AspNet.Mvc.Abstractions;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Infrastructure namespace Microsoft.AspNet.Mvc.Infrastructure
{ {
@ -17,8 +17,13 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
/// </summary> /// </summary>
/// <param name="items">The result of action discovery</param> /// <param name="items">The result of action discovery</param>
/// <param name="version">The unique version of discovered actions.</param> /// <param name="version">The unique version of discovered actions.</param>
public ActionDescriptorsCollection([NotNull] IReadOnlyList<ActionDescriptor> items, int version) public ActionDescriptorsCollection(IReadOnlyList<ActionDescriptor> items, int version)
{ {
if (items == null)
{
throw new ArgumentNullException(nameof(items));
}
Items = items; Items = items;
Version = version; Version = version;
} }

View File

@ -11,7 +11,6 @@ using Microsoft.AspNet.Mvc.ActionConstraints;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.Routing;
using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.Infrastructure namespace Microsoft.AspNet.Mvc.Infrastructure
@ -35,8 +34,13 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
_logger = loggerFactory.CreateLogger<DefaultActionSelector>(); _logger = loggerFactory.CreateLogger<DefaultActionSelector>();
} }
public Task<ActionDescriptor> SelectAsync([NotNull] RouteContext context) public Task<ActionDescriptor> SelectAsync(RouteContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var tree = _decisionTreeProvider.DecisionTree; var tree = _decisionTreeProvider.DecisionTree;
var matchingRouteConstraints = tree.Select(context.RouteData.Values); var matchingRouteConstraints = tree.Select(context.RouteData.Values);
@ -169,7 +173,7 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
_logger.LogVerbose( _logger.LogVerbose(
"Action '{ActionDisplayName}' with id '{ActionId}' did not match the " + "Action '{ActionDisplayName}' with id '{ActionId}' did not match the " +
"constraint '{ActionConstraint}'", "constraint '{ActionConstraint}'",
candidate.Action.DisplayName, candidate.Action.DisplayName,
candidate.Action.Id, candidate.Action.Id,
constraint); constraint);
@ -216,8 +220,13 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
// any link - this gives WebFX a chance to 'veto' the values provided by a route. // any link - this gives WebFX a chance to 'veto' the values provided by a route.
// //
// This method does not take httpmethod or dynamic action constraints into account. // This method does not take httpmethod or dynamic action constraints into account.
public virtual bool HasValidAction([NotNull] VirtualPathContext context) public virtual bool HasValidAction(VirtualPathContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (context.ProvidedValues == null) if (context.ProvidedValues == null)
{ {
// We need the route's values to be able to double check our work. // We need the route's values to be able to double check our work.

View File

@ -4,7 +4,6 @@
using System; using System;
using System.Collections.Concurrent; using System.Collections.Concurrent;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Infrastructure namespace Microsoft.AspNet.Mvc.Infrastructure
{ {
@ -21,9 +20,19 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
/// <inheritdoc/> /// <inheritdoc/>
public TInstance CreateInstance<TInstance>( public TInstance CreateInstance<TInstance>(
[NotNull] IServiceProvider serviceProvider, IServiceProvider serviceProvider,
[NotNull] Type implementationType) Type implementationType)
{ {
if (serviceProvider == null)
{
throw new ArgumentNullException(nameof(serviceProvider));
}
if (implementationType == null)
{
throw new ArgumentNullException(nameof(implementationType));
}
var createFactory = _typeActivatorCache.GetOrAdd(implementationType, _createFactory); var createFactory = _typeActivatorCache.GetOrAdd(implementationType, _createFactory);
return (TInstance)createFactory(serviceProvider, arguments: null); return (TInstance)createFactory(serviceProvider, arguments: null);
} }

View File

@ -10,7 +10,6 @@ using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Internal; using Microsoft.AspNet.Mvc.Internal;
using Microsoft.AspNet.Routing; using Microsoft.AspNet.Routing;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Logging; using Microsoft.Framework.Logging;
namespace Microsoft.AspNet.Mvc.Infrastructure namespace Microsoft.AspNet.Mvc.Infrastructure
@ -23,8 +22,13 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
private ILogger _logger; private ILogger _logger;
private TelemetrySource _telemetry; private TelemetrySource _telemetry;
public VirtualPathData GetVirtualPath([NotNull] VirtualPathContext context) public VirtualPathData GetVirtualPath(VirtualPathContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
EnsureServices(context.Context); EnsureServices(context.Context);
// The contract of this method is to check that the values coming in from the route are valid; // The contract of this method is to check that the values coming in from the route are valid;
@ -35,8 +39,13 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
return null; return null;
} }
public async Task RouteAsync([NotNull] RouteContext context) public async Task RouteAsync(RouteContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var services = context.HttpContext.RequestServices; var services = context.HttpContext.RequestServices;
// Verify if AddMvc was done before calling UseMvc // Verify if AddMvc was done before calling UseMvc
@ -75,7 +84,7 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
{ {
_telemetry.WriteTelemetry( _telemetry.WriteTelemetry(
"Microsoft.AspNet.Mvc.BeforeAction", "Microsoft.AspNet.Mvc.BeforeAction",
new { actionDescriptor, httpContext = context.HttpContext, routeData = context.RouteData}); new { actionDescriptor, httpContext = context.HttpContext, routeData = context.RouteData });
} }
using (_logger.BeginScope("ActionId: {ActionId}", actionDescriptor.Id)) using (_logger.BeginScope("ActionId: {ActionId}", actionDescriptor.Id))
@ -106,7 +115,7 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
{ {
var actionContext = new ActionContext(context.HttpContext, context.RouteData, actionDescriptor); var actionContext = new ActionContext(context.HttpContext, context.RouteData, actionDescriptor);
_actionContextAccessor.ActionContext = actionContext; _actionContextAccessor.ActionContext = actionContext;
var invoker = _actionInvokerFactory.CreateInvoker(actionContext); var invoker = _actionInvokerFactory.CreateInvoker(actionContext);
if (invoker == null) if (invoker == null)
{ {

View File

@ -4,7 +4,6 @@
using System; using System;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Routing; using Microsoft.AspNet.Mvc.Routing;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Infrastructure namespace Microsoft.AspNet.Mvc.Infrastructure
{ {
@ -30,9 +29,14 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
/// or <see cref="RouteKeyHandling.DenyKey"/>. /// or <see cref="RouteKeyHandling.DenyKey"/>.
/// </param> /// </param>
protected RouteConstraintAttribute( protected RouteConstraintAttribute(
[NotNull] string routeKey, string routeKey,
RouteKeyHandling keyHandling) RouteKeyHandling keyHandling)
{ {
if (routeKey == null)
{
throw new ArgumentNullException(nameof(routeKey));
}
RouteKey = routeKey; RouteKey = routeKey;
RouteKeyHandling = keyHandling; RouteKeyHandling = keyHandling;
@ -56,10 +60,20 @@ namespace Microsoft.AspNet.Mvc.Infrastructure
/// Set to true to negate this constraint on all actions that do not define a behavior for this route key. /// Set to true to negate this constraint on all actions that do not define a behavior for this route key.
/// </param> /// </param>
protected RouteConstraintAttribute( protected RouteConstraintAttribute(
[NotNull]string routeKey, string routeKey,
[NotNull]string routeValue, string routeValue,
bool blockNonAttributedActions) bool blockNonAttributedActions)
{ {
if (routeKey == null)
{
throw new ArgumentNullException(nameof(routeKey));
}
if (routeValue == null)
{
throw new ArgumentNullException(nameof(routeValue));
}
RouteKey = routeKey; RouteKey = routeKey;
RouteValue = routeValue; RouteValue = routeValue;
BlockNonAttributedActions = blockNonAttributedActions; BlockNonAttributedActions = blockNonAttributedActions;

View File

@ -1,15 +1,20 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Internal namespace Microsoft.AspNet.Mvc.Internal
{ {
public class MvcBuilder : IMvcBuilder public class MvcBuilder : IMvcBuilder
{ {
public MvcBuilder([NotNull] IServiceCollection services) public MvcBuilder(IServiceCollection services)
{ {
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
Services = services; Services = services;
} }

View File

@ -1,15 +1,20 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Internal namespace Microsoft.AspNet.Mvc.Internal
{ {
public class MvcCoreBuilder : IMvcCoreBuilder public class MvcCoreBuilder : IMvcCoreBuilder
{ {
public MvcCoreBuilder([NotNull] IServiceCollection services) public MvcCoreBuilder(IServiceCollection services)
{ {
if (services == null)
{
throw new ArgumentNullException(nameof(services));
}
Services = services; Services = services;
} }

View File

@ -1,13 +1,10 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
#if DNX451
using System; using System;
#endif
using System.IO; using System.IO;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.Internal namespace Microsoft.AspNet.Mvc.Internal
{ {
@ -24,8 +21,13 @@ namespace Microsoft.AspNet.Mvc.Internal
/// Initializes a new <see cref="NonDisposableStream"/>. /// Initializes a new <see cref="NonDisposableStream"/>.
/// </summary> /// </summary>
/// <param name="innerStream">The stream which should not be closed or flushed.</param> /// <param name="innerStream">The stream which should not be closed or flushed.</param>
public NonDisposableStream([NotNull] Stream innerStream) public NonDisposableStream(Stream innerStream)
{ {
if (innerStream == null)
{
throw new ArgumentNullException(nameof(innerStream));
}
_innerStream = innerStream; _innerStream = innerStream;
} }

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
@ -17,8 +16,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public class ArrayModelBinder<TElement> : CollectionModelBinder<TElement> public class ArrayModelBinder<TElement> : CollectionModelBinder<TElement>
{ {
/// <inheritdoc /> /// <inheritdoc />
public override Task<ModelBindingResult> BindModelAsync([NotNull] ModelBindingContext bindingContext) public override Task<ModelBindingResult> BindModelAsync(ModelBindingContext bindingContext)
{ {
if (bindingContext == null)
{
throw new ArgumentNullException(nameof(bindingContext));
}
if (bindingContext.ModelMetadata.IsReadOnly) if (bindingContext.ModelMetadata.IsReadOnly)
{ {
return ModelBindingResult.NoResultAsync; return ModelBindingResult.NoResultAsync;
@ -51,8 +55,12 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void CopyToModel([NotNull] object target, IEnumerable<TElement> sourceCollection) protected override void CopyToModel(object target, IEnumerable<TElement> sourceCollection)
{ {
if (target == null)
{
throw new ArgumentNullException(nameof(target));
}
// Do not attempt to copy values into an array because an array's length is immutable. This choice is also // Do not attempt to copy values into an array because an array's length is immutable. This choice is also
// consistent with MutableObjectModelBinder's handling of a read-only array property. // consistent with MutableObjectModelBinder's handling of a read-only array property.
} }

View File

@ -2,9 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
@ -33,8 +31,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// The <see cref="ModelBinding.BindingSource"/>. Must be a single-source (non-composite) with /// The <see cref="ModelBinding.BindingSource"/>. Must be a single-source (non-composite) with
/// <see cref="ModelBinding.BindingSource.IsGreedy"/> equal to <c>false</c>. /// <see cref="ModelBinding.BindingSource.IsGreedy"/> equal to <c>false</c>.
/// </param> /// </param>
public BindingSourceValueProvider([NotNull] BindingSource bindingSource) public BindingSourceValueProvider(BindingSource bindingSource)
{ {
if (bindingSource == null)
{
throw new ArgumentNullException(nameof(bindingSource));
}
if (bindingSource.IsGreedy) if (bindingSource.IsGreedy)
{ {
var message = Resources.FormatBindingSource_CannotBeGreedy( var message = Resources.FormatBindingSource_CannotBeGreedy(
@ -68,6 +71,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <inheritdoc /> /// <inheritdoc />
public virtual IValueProvider Filter(BindingSource bindingSource) public virtual IValueProvider Filter(BindingSource bindingSource)
{ {
if (bindingSource == null)
{
throw new ArgumentNullException(nameof(bindingSource));
}
if (bindingSource.CanAcceptDataFrom(BindingSource)) if (bindingSource.CanAcceptDataFrom(BindingSource))
{ {
return this; return this;

View File

@ -6,7 +6,6 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.Formatters; using Microsoft.AspNet.Mvc.Formatters;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
@ -42,8 +41,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <returns> /// <returns>
/// A <see cref="Task{ModelBindingResult}"/> which when completed returns a <see cref="ModelBindingResult"/>. /// A <see cref="Task{ModelBindingResult}"/> which when completed returns a <see cref="ModelBindingResult"/>.
/// </returns> /// </returns>
private async Task<ModelBindingResult> BindModelCoreAsync([NotNull] ModelBindingContext bindingContext) private async Task<ModelBindingResult> BindModelCoreAsync(ModelBindingContext bindingContext)
{ {
if (bindingContext == null)
{
throw new ArgumentNullException(nameof(bindingContext));
}
// For compatibility with MVC 5.0 for top level object we want to consider an empty key instead of // For compatibility with MVC 5.0 for top level object we want to consider an empty key instead of
// the parameter name/a custom name. In all other cases (like when binding body to a property) we // the parameter name/a custom name. In all other cases (like when binding body to a property) we
// consider the entire ModelName as a prefix. // consider the entire ModelName as a prefix.

View File

@ -3,7 +3,6 @@
using System; using System;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
@ -13,8 +12,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public class ByteArrayModelBinder : IModelBinder public class ByteArrayModelBinder : IModelBinder
{ {
/// <inheritdoc /> /// <inheritdoc />
public Task<ModelBindingResult> BindModelAsync([NotNull] ModelBindingContext bindingContext) public Task<ModelBindingResult> BindModelAsync(ModelBindingContext bindingContext)
{ {
if (bindingContext == null)
{
throw new ArgumentNullException(nameof(bindingContext));
}
// This method is optimized to use cached tasks when possible and avoid allocating // This method is optimized to use cached tasks when possible and avoid allocating
// using Task.FromResult. If you need to make changes of this nature, profile // using Task.FromResult. If you need to make changes of this nature, profile
// allocations afterwards and look for Task<ModelBindingResult>. // allocations afterwards and look for Task<ModelBindingResult>.

View File

@ -12,7 +12,6 @@ using System.Reflection;
#endif #endif
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.ModelBinding.Validation; using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
@ -23,8 +22,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public class CollectionModelBinder<TElement> : ICollectionModelBinder public class CollectionModelBinder<TElement> : ICollectionModelBinder
{ {
/// <inheritdoc /> /// <inheritdoc />
public virtual async Task<ModelBindingResult> BindModelAsync([NotNull] ModelBindingContext bindingContext) public virtual async Task<ModelBindingResult> BindModelAsync(ModelBindingContext bindingContext)
{ {
if (bindingContext == null)
{
throw new ArgumentNullException(nameof(bindingContext));
}
ModelBindingHelper.ValidateBindingContext(bindingContext); ModelBindingHelper.ValidateBindingContext(bindingContext);
var model = bindingContext.Model; var model = bindingContext.Model;
@ -303,8 +307,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <param name="sourceCollection"> /// <param name="sourceCollection">
/// Collection of values retrieved from value providers. Or <c>null</c> if nothing was bound. /// Collection of values retrieved from value providers. Or <c>null</c> if nothing was bound.
/// </param> /// </param>
protected virtual void CopyToModel([NotNull] object target, IEnumerable<TElement> sourceCollection) protected virtual void CopyToModel(object target, IEnumerable<TElement> sourceCollection)
{ {
if (target == null)
{
throw new ArgumentNullException(nameof(target));
}
var targetCollection = target as ICollection<TElement>; var targetCollection = target as ICollection<TElement>;
Debug.Assert(targetCollection != null, "This binder is instantiated only for ICollection<T> model types."); Debug.Assert(targetCollection != null, "This binder is instantiated only for ICollection<T> model types.");

View File

@ -5,9 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.ModelBinding.Validation; using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
@ -25,16 +23,26 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// Initializes a new instance of the CompositeModelBinder class. /// Initializes a new instance of the CompositeModelBinder class.
/// </summary> /// </summary>
/// <param name="modelBinders">A collection of <see cref="IModelBinder"/> instances.</param> /// <param name="modelBinders">A collection of <see cref="IModelBinder"/> instances.</param>
public CompositeModelBinder([NotNull] IEnumerable<IModelBinder> modelBinders) public CompositeModelBinder(IEnumerable<IModelBinder> modelBinders)
{ {
if (modelBinders == null)
{
throw new ArgumentNullException(nameof(modelBinders));
}
ModelBinders = new List<IModelBinder>(modelBinders); ModelBinders = new List<IModelBinder>(modelBinders);
} }
/// <inheritdoc /> /// <inheritdoc />
public IReadOnlyList<IModelBinder> ModelBinders { get; } public IReadOnlyList<IModelBinder> ModelBinders { get; }
public virtual Task<ModelBindingResult> BindModelAsync([NotNull] ModelBindingContext bindingContext) public virtual Task<ModelBindingResult> BindModelAsync(ModelBindingContext bindingContext)
{ {
if (bindingContext == null)
{
throw new ArgumentNullException(nameof(bindingContext));
}
var newBindingContext = CreateNewBindingContext(bindingContext); var newBindingContext = CreateNewBindingContext(bindingContext);
if (newBindingContext == null) if (newBindingContext == null)
{ {

View File

@ -6,7 +6,6 @@ using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
@ -47,9 +46,19 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// created. /// created.
/// </returns> /// </returns>
public static async Task<CompositeValueProvider> CreateAsync( public static async Task<CompositeValueProvider> CreateAsync(
[NotNull] IEnumerable<IValueProviderFactory> factories, IEnumerable<IValueProviderFactory> factories,
[NotNull] ValueProviderFactoryContext context) ValueProviderFactoryContext context)
{ {
if (factories == null)
{
throw new ArgumentNullException(nameof(factories));
}
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
var composite = new CompositeValueProvider(); var composite = new CompositeValueProvider();
foreach (var valueProvidersFactory in factories) foreach (var valueProvidersFactory in factories)
{ {
@ -114,20 +123,35 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void InsertItem(int index, [NotNull] IValueProvider item) protected override void InsertItem(int index, IValueProvider item)
{ {
if (item == null)
{
throw new ArgumentNullException(nameof(item));
}
base.InsertItem(index, item); base.InsertItem(index, item);
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void SetItem(int index, [NotNull] IValueProvider item) protected override void SetItem(int index, IValueProvider item)
{ {
if (item == null)
{
throw new ArgumentNullException(nameof(item));
}
base.SetItem(index, item); base.SetItem(index, item);
} }
/// <inheritdoc /> /// <inheritdoc />
public IValueProvider Filter(BindingSource bindingSource) public IValueProvider Filter(BindingSource bindingSource)
{ {
if (bindingSource == null)
{
throw new ArgumentNullException(nameof(bindingSource));
}
var filteredValueProviders = new List<IValueProvider>(); var filteredValueProviders = new List<IValueProvider>();
foreach (var valueProvider in this.OfType<IBindingSourceValueProvider>()) foreach (var valueProvider in this.OfType<IBindingSourceValueProvider>())
{ {

View File

@ -1,10 +1,9 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.Threading.Tasks;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
@ -12,7 +11,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// An <see cref="IValueProvider"/> adapter for data stored in an /// An <see cref="IValueProvider"/> adapter for data stored in an
/// <see cref="IDictionary{string, object}"/>. /// <see cref="IDictionary{string, object}"/>.
/// </summary> /// </summary>
public class DictionaryBasedValueProvider: BindingSourceValueProvider public class DictionaryBasedValueProvider : BindingSourceValueProvider
{ {
private readonly IDictionary<string, object> _values; private readonly IDictionary<string, object> _values;
private PrefixContainer _prefixContainer; private PrefixContainer _prefixContainer;
@ -23,10 +22,20 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
/// <param name="bindingSource">The <see cref="BindingSource"/> of the data.</param> /// <param name="bindingSource">The <see cref="BindingSource"/> of the data.</param>
/// <param name="values">The values.</param> /// <param name="values">The values.</param>
public DictionaryBasedValueProvider( public DictionaryBasedValueProvider(
[NotNull] BindingSource bindingSource, BindingSource bindingSource,
[NotNull] IDictionary<string, object> values) IDictionary<string, object> values)
: base(bindingSource) : base(bindingSource)
{ {
if (bindingSource == null)
{
throw new ArgumentNullException(nameof(bindingSource));
}
if (values == null)
{
throw new ArgumentNullException(nameof(values));
}
_values = values; _values = values;
} }
@ -50,8 +59,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
/// <inheritdoc /> /// <inheritdoc />
public override ValueProviderResult GetValue([NotNull] string key) public override ValueProviderResult GetValue(string key)
{ {
if (key == null)
{
throw new ArgumentNullException(nameof(key));
}
object value; object value;
if (_values.TryGetValue(key, out value)) if (_values.TryGetValue(key, out value))
{ {

View File

@ -10,7 +10,6 @@ using System.Reflection;
#endif #endif
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.ModelBinding.Validation; using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.Framework.Internal;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
@ -22,8 +21,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public class DictionaryModelBinder<TKey, TValue> : CollectionModelBinder<KeyValuePair<TKey, TValue>> public class DictionaryModelBinder<TKey, TValue> : CollectionModelBinder<KeyValuePair<TKey, TValue>>
{ {
/// <inheritdoc /> /// <inheritdoc />
public override async Task<ModelBindingResult> BindModelAsync([NotNull] ModelBindingContext bindingContext) public override async Task<ModelBindingResult> BindModelAsync(ModelBindingContext bindingContext)
{ {
if (bindingContext == null)
{
throw new ArgumentNullException(nameof(bindingContext));
}
var result = await base.BindModelAsync(bindingContext); var result = await base.BindModelAsync(bindingContext);
if (!result.IsModelSet) if (!result.IsModelSet)
{ {

View File

@ -1,6 +1,7 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Mvc.Core; using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.ModelBinding.Metadata; using Microsoft.AspNet.Mvc.ModelBinding.Metadata;
@ -22,6 +23,11 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public void GetBindingMetadata(BindingMetadataProviderContext context) public void GetBindingMetadata(BindingMetadataProviderContext context)
{ {
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
// Don't bother with ModelBindingMessageProvider copy constructor. No other provider can change the // Don't bother with ModelBindingMessageProvider copy constructor. No other provider can change the
// delegates. // delegates.
context.BindingMetadata.ModelBindingMessageProvider = _messageProvider; context.BindingMetadata.ModelBindingMessageProvider = _messageProvider;

View File

@ -8,7 +8,6 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.ModelBinding.Validation; using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.Framework.Internal;
using Microsoft.Framework.Primitives; using Microsoft.Framework.Primitives;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
@ -19,8 +18,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public class FormCollectionModelBinder : IModelBinder public class FormCollectionModelBinder : IModelBinder
{ {
/// <inheritdoc /> /// <inheritdoc />
public Task<ModelBindingResult> BindModelAsync([NotNull] ModelBindingContext bindingContext) public Task<ModelBindingResult> BindModelAsync(ModelBindingContext bindingContext)
{ {
if (bindingContext == null)
{
throw new ArgumentNullException(nameof(bindingContext));
}
// This method is optimized to use cached tasks when possible and avoid allocating // This method is optimized to use cached tasks when possible and avoid allocating
// using Task.FromResult. If you need to make changes of this nature, profile // using Task.FromResult. If you need to make changes of this nature, profile
// allocations afterwards and look for Task<ModelBindingResult>. // allocations afterwards and look for Task<ModelBindingResult>.

View File

@ -11,7 +11,6 @@ using System.Reflection;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNet.Http; using Microsoft.AspNet.Http;
using Microsoft.AspNet.Mvc.ModelBinding.Validation; using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.Framework.Internal;
using Microsoft.Net.Http.Headers; using Microsoft.Net.Http.Headers;
namespace Microsoft.AspNet.Mvc.ModelBinding namespace Microsoft.AspNet.Mvc.ModelBinding
@ -22,8 +21,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
public class FormFileModelBinder : IModelBinder public class FormFileModelBinder : IModelBinder
{ {
/// <inheritdoc /> /// <inheritdoc />
public Task<ModelBindingResult> BindModelAsync([NotNull] ModelBindingContext bindingContext) public Task<ModelBindingResult> BindModelAsync(ModelBindingContext bindingContext)
{ {
if (bindingContext == null)
{
throw new ArgumentNullException(nameof(bindingContext));
}
// This method is optimized to use cached tasks when possible and avoid allocating // This method is optimized to use cached tasks when possible and avoid allocating
// using Task.FromResult. If you need to make changes of this nature, profile // using Task.FromResult. If you need to make changes of this nature, profile
// allocations afterwards and look for Task<ModelBindingResult>. // allocations afterwards and look for Task<ModelBindingResult>.
@ -38,7 +42,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
} }
private async Task<ModelBindingResult> BindModelCoreAsync(ModelBindingContext bindingContext) private async Task<ModelBindingResult> BindModelCoreAsync(ModelBindingContext bindingContext)
{ {
object value; object value;
if (bindingContext.ModelType == typeof(IFormFile)) if (bindingContext.ModelType == typeof(IFormFile))
{ {
@ -56,13 +60,13 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
Debug.Fail("We shouldn't be called without a matching type."); Debug.Fail("We shouldn't be called without a matching type.");
return ModelBindingResult.NoResult; return ModelBindingResult.NoResult;
} }
if (value == null) if (value == null)
{ {
return ModelBindingResult.Failed(bindingContext.ModelName); return ModelBindingResult.Failed(bindingContext.ModelName);
} }
else else
{ {
bindingContext.ValidationState.Add(value, new ValidationStateEntry() { SuppressValidation = true }); bindingContext.ValidationState.Add(value, new ValidationStateEntry() { SuppressValidation = true });
bindingContext.ModelState.SetModelValue( bindingContext.ModelState.SetModelValue(
bindingContext.ModelName, bindingContext.ModelName,

Some files were not shown because too many files have changed in this diff Show More