This repository was archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving IModelValidatorProvider to Options
Fixes #879
- Loading branch information
Showing
34 changed files
with
605 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/Microsoft.AspNet.Mvc.Core/OptionDescriptors/DefaultModelValidatorProviderProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. | ||
// 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 Microsoft.AspNet.Mvc.ModelBinding; | ||
using Microsoft.Framework.DependencyInjection; | ||
using Microsoft.Framework.OptionsModel; | ||
|
||
namespace Microsoft.AspNet.Mvc.OptionDescriptors | ||
{ | ||
/// <inheritdoc /> | ||
public class DefaultModelValidatorProviderProvider : OptionDescriptorBasedProvider<IModelValidatorProvider>, | ||
IModelValidatorProviderProvider | ||
{ | ||
/// <summary> | ||
/// Initializes a new instance of the <see cref="DefaultModelValidatorProviderProvider"/> class. | ||
/// </summary> | ||
/// <param name="options">An accessor to the <see cref="MvcOptions"/> configured for this application.</param> | ||
/// <param name="typeActivator">An <see cref="ITypeActivator"/> instance used to instantiate types.</param> | ||
/// <param name="serviceProvider">A <see cref="IServiceProvider"/> instance that retrieves services from the | ||
/// service collection.</param> | ||
public DefaultModelValidatorProviderProvider( | ||
IOptionsAccessor<MvcOptions> optionsAccessor, | ||
ITypeActivator typeActivator, | ||
IServiceProvider serviceProvider) | ||
: base(optionsAccessor.Options.ModelValidatorProviders, typeActivator, serviceProvider) | ||
{ | ||
} | ||
|
||
/// <inheritdoc /> | ||
public IReadOnlyList<IModelValidatorProvider> ModelValidatorProviders | ||
{ | ||
get { return Options; } | ||
} | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/Microsoft.AspNet.Mvc.Core/OptionDescriptors/ModelValidatorProviderDescriptor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using Microsoft.AspNet.Mvc.ModelBinding; | ||
|
||
namespace Microsoft.AspNet.Mvc.OptionDescriptors | ||
{ | ||
/// <summary> | ||
/// Encapsulates information that describes an <see cref="IModelValidatorProvider"/>. | ||
/// </summary> | ||
public class ModelValidatorProviderDescriptor : OptionDescriptor<IModelValidatorProvider> | ||
{ | ||
/// <summary> | ||
/// Creates a new instance of <see cref="ModelValidatorProviderDescriptor"/>. | ||
/// </summary> | ||
/// <param name="type">A type that represents a <see cref="IModelValidatorProvider"/>.</param> | ||
public ModelValidatorProviderDescriptor([NotNull] Type type) | ||
: base(type) | ||
{ | ||
} | ||
|
||
/// <summary> | ||
/// Creates a new instance of <see cref="ModelValidatorProviderDescriptor"/> with the specified instance. | ||
/// </summary> | ||
/// <param name="option">An instance of <see cref="IModelValidatorProvider"/>.</param> | ||
public ModelValidatorProviderDescriptor([NotNull] IModelValidatorProvider validatorProvider) | ||
: base(validatorProvider) | ||
{ | ||
} | ||
} | ||
} |
94 changes: 94 additions & 0 deletions
94
...Microsoft.AspNet.Mvc.Core/OptionDescriptors/ModelValidatorProviderDescriptorExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. | ||
// 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 Microsoft.AspNet.Mvc.ModelBinding; | ||
using Microsoft.AspNet.Mvc.OptionDescriptors; | ||
|
||
namespace Microsoft.AspNet.Mvc | ||
{ | ||
/// <summary> | ||
/// Extension methods for adding validator provider to a collection. | ||
/// </summary> | ||
public static class ModelValidatorProviderDescriptorExtensions | ||
{ | ||
/// <summary> | ||
/// Adds a type representing a <see cref="IModelValidatorProvider"/> to <paramref name="descriptors"/>. | ||
/// </summary> | ||
/// <param name="descriptors">A list of <see cref="ModelValidatorProviderDescriptor"/>.</param> | ||
/// <param name="modelValidatorProviderType">Type representing an <see cref="IModelValidatorProvider"/></param> | ||
/// <returns>A <see cref="ModelValidatorProviderDescriptor"/> representing the added instance.</returns> | ||
public static ModelValidatorProviderDescriptor Add( | ||
[NotNull] this IList<ModelValidatorProviderDescriptor> descriptors, | ||
[NotNull] Type modelValidatorProviderType) | ||
{ | ||
var descriptor = new ModelValidatorProviderDescriptor(modelValidatorProviderType); | ||
descriptors.Add(descriptor); | ||
return descriptor; | ||
} | ||
|
||
/// <summary> | ||
/// Inserts a type representing a <see cref="IModelValidatorProvider"/> in to <paramref name="descriptors"/> at | ||
/// the specified <paramref name="index"/>. | ||
/// </summary> | ||
/// <param name="descriptors">A list of <see cref="ModelValidatorProviderDescriptor"/>.</param> | ||
/// <param name="index">The zero-based index at which <paramref name="modelValidatorProviderType"/> | ||
/// should be inserted.</param> | ||
/// <param name="modelValidatorProviderType">Type representing an <see cref="IModelValidatorProvider"/></param> | ||
/// <returns>A <see cref="ModelValidatorProviderDescriptor"/> representing the inserted instance.</returns> | ||
public static ModelValidatorProviderDescriptor Insert( | ||
[NotNull] this IList<ModelValidatorProviderDescriptor> descriptors, | ||
int index, | ||
[NotNull] Type modelValidatorProviderType) | ||
{ | ||
if (index < 0 || index > descriptors.Count) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(index)); | ||
} | ||
|
||
var descriptor = new ModelValidatorProviderDescriptor(modelValidatorProviderType); | ||
descriptors.Insert(index, descriptor); | ||
return descriptor; | ||
} | ||
|
||
/// <summary> | ||
/// Adds an <see cref="IModelValidatorProvider"/> to <paramref name="descriptors"/>. | ||
/// </summary> | ||
/// <param name="descriptors">A list of <see cref="ModelValidatorProviderDescriptor"/>.</param> | ||
/// <param name="modelValidatorProvider">An <see cref="IModelBinder"/> instance.</param> | ||
/// <returns>A <see cref="ModelValidatorProviderDescriptor"/> representing the added instance.</returns> | ||
public static ModelValidatorProviderDescriptor Add( | ||
[NotNull] this IList<ModelValidatorProviderDescriptor> descriptors, | ||
[NotNull] IModelValidatorProvider modelValidatorProvider) | ||
{ | ||
var descriptor = new ModelValidatorProviderDescriptor(modelValidatorProvider); | ||
descriptors.Add(descriptor); | ||
return descriptor; | ||
} | ||
|
||
/// <summary> | ||
/// Insert an <see cref="IModelValidatorProvider"/> in to <paramref name="descriptors"/> at the specified | ||
/// <paramref name="index"/>. | ||
/// </summary> | ||
/// <param name="descriptors">A list of <see cref="ModelValidatorProviderDescriptor"/>.</param> | ||
/// <param name="index">The zero-based index at which <paramref name="modelValidatorProvider"/> | ||
/// should be inserted.</param> | ||
/// <param name="modelValidatorProvider">An <see cref="IModelBinder"/> instance.</param> | ||
/// <returns>A <see cref="ModelValidatorProviderDescriptor"/> representing the added instance.</returns> | ||
public static ModelValidatorProviderDescriptor Insert( | ||
[NotNull] this IList<ModelValidatorProviderDescriptor> descriptors, | ||
int index, | ||
[NotNull] IModelValidatorProvider modelValidatorProvider) | ||
{ | ||
if (index < 0 || index > descriptors.Count) | ||
{ | ||
throw new ArgumentOutOfRangeException(nameof(index)); | ||
} | ||
|
||
var descriptor = new ModelValidatorProviderDescriptor(modelValidatorProvider); | ||
descriptors.Insert(index, descriptor); | ||
return descriptor; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.