This repository has been 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
/
MvcDataAnnotationsMvcBuilderExtensions.cs
53 lines (47 loc) · 1.95 KB
/
MvcDataAnnotationsMvcBuilderExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// 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.
using System;
using Microsoft.AspNetCore.Mvc.DataAnnotations;
using Microsoft.AspNetCore.Mvc.DataAnnotations.Internal;
namespace Microsoft.Extensions.DependencyInjection
{
/// <summary>
/// Extension methods for configuring MVC data annotations localization.
/// </summary>
public static class MvcDataAnnotationsMvcBuilderExtensions
{
/// <summary>
/// Adds MVC data annotations localization to the application.
/// </summary>
/// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
/// <returns>The <see cref="IMvcBuilder"/>.</returns>
public static IMvcBuilder AddDataAnnotationsLocalization(this IMvcBuilder builder)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
return AddDataAnnotationsLocalization(builder, setupAction: null);
}
/// <summary>
/// Adds MVC data annotations localization to the application.
/// </summary>
/// <param name="builder">The <see cref="IMvcBuilder"/>.</param>
/// <param name="setupAction">The action to configure <see cref="MvcDataAnnotationsLocalizationOptions"/>.
/// </param>
/// <returns>The <see cref="IMvcBuilder"/>.</returns>
public static IMvcBuilder AddDataAnnotationsLocalization(
this IMvcBuilder builder,
Action<MvcDataAnnotationsLocalizationOptions> setupAction)
{
if (builder == null)
{
throw new ArgumentNullException(nameof(builder));
}
DataAnnotationsLocalizationServices.AddDataAnnotationsLocalizationServices(
builder.Services,
setupAction);
return builder;
}
}
}