-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
ServiceCollectionExtensions.cs
39 lines (34 loc) · 1.41 KB
/
ServiceCollectionExtensions.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
using Bet.AspNetCore.ReCapture;
using Bet.AspNetCore.ReCapture.Google;
using Microsoft.Extensions.Configuration;
namespace Microsoft.Extensions.DependencyInjection
{
public static class ServiceCollectionExtensions
{
/// <summary>
/// Add Google ReCapture Validation to your website.
/// </summary>
/// <param name="services">The default <see cref="IServiceCollection"/> for the application.</param>
/// <param name="configuration">The default <see cref="IConfiguration"/> for the application.</param>
/// <param name="validateConfigurations">The default value is true. Throws exception if the required values are absent.</param>
/// <returns></returns>
public static IServiceCollection AddReCapture(
this IServiceCollection services,
IConfiguration configuration,
bool validateConfigurations = true)
{
if (validateConfigurations)
{
services.AddConfigurationValidation();
services.ConfigureWithDataAnnotationsValidation<GoogleReCaptchaOptions>(configuration);
}
else
{
services.Configure<GoogleReCaptchaOptions>(configuration);
}
services.AddTransient<GoogleReCaptureFilter>();
services.AddHttpClient<GoolgeReCaptureService>();
return services;
}
}
}