diff --git a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/ReCaptchaLoginFilter.cs b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/ReCaptchaLoginFilter.cs index d02a07fe56e..b34e9c71be5 100644 --- a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/ReCaptchaLoginFilter.cs +++ b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/ReCaptchaLoginFilter.cs @@ -17,6 +17,8 @@ public class ReCaptchaLoginFilter : IAsyncResultFilter private readonly ReCaptchaService _reCaptchaService; private readonly IShapeFactory _shapeFactory; + private ReCaptchaSettings _reCaptchaSettings; + public ReCaptchaLoginFilter( ILayoutAccessor layoutAccessor, ISiteService siteService, @@ -38,9 +40,12 @@ public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultE return; } - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + if (_reCaptchaSettings == null) + { + _reCaptchaSettings = (await _siteService.GetSiteSettingsAsync()).As(); + } - if (!settings.IsValid()) + if (!_reCaptchaSettings.IsValid()) { await next(); return; diff --git a/src/OrchardCore/OrchardCore.ReCaptcha.Core/ServiceCollectionExtensions.cs b/src/OrchardCore/OrchardCore.ReCaptcha.Core/ServiceCollectionExtensions.cs index 16444224da6..c65d2109119 100644 --- a/src/OrchardCore/OrchardCore.ReCaptcha.Core/ServiceCollectionExtensions.cs +++ b/src/OrchardCore/OrchardCore.ReCaptcha.Core/ServiceCollectionExtensions.cs @@ -14,7 +14,7 @@ public static class ServiceCollectionExtensions public static IServiceCollection AddReCaptcha(this IServiceCollection services, Action configure = null) { // c.f. https://learn.microsoft.com/en-us/dotnet/architecture/microservices/implement-resilient-applications/use-httpclientfactory-to-implement-resilient-http-requests - services.AddScoped() + services.AddSingleton() .AddHttpClient(nameof(ReCaptchaService)) .AddTransientHttpErrorPolicy(policy => policy.WaitAndRetryAsync(3, attempt => TimeSpan.FromSeconds(0.5 * attempt)));