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
Moving IModelValidatorProvider to Options #1055
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: add an 's' ->
<see cref="IModelValidatorProvider" />s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍