Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use IAsyncConfigureOptions #15125

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace OrchardCore.Facebook.Services;

public class FacebookSettingsConfiguration : IConfigureOptions<FacebookSettings>
public class FacebookSettingsConfiguration : IAsyncConfigureOptions<FacebookSettings>
{
private readonly IFacebookService _facebookService;
private readonly ShellSettings _shellSettings;
Expand All @@ -24,11 +24,9 @@ public FacebookSettingsConfiguration(
_logger = logger;
}

public void Configure(FacebookSettings options)
public async ValueTask ConfigureAsync(FacebookSettings options)
{
var settings = GetFacebookSettingsAsync()
.GetAwaiter()
.GetResult();
var settings = await GetFacebookSettingsAsync();

if (settings != null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.Extensions.Options;

namespace OrchardCore.Facebook.Settings
{
public class FacebookSettings
public class FacebookSettings : IAsyncOptions
{
public string AppId { get; set; }
public string AppSecret { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/OrchardCore.Modules/OrchardCore.Facebook/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override void ConfigureServices(IServiceCollection services)
services.AddRecipeExecutionStep<FacebookSettingsStep>();

services.AddTransient<IConfigureOptions<ResourceManagementOptions>, ResourceManagementOptionsConfiguration>();
services.AddTransient<IConfigureOptions<FacebookSettings>, FacebookSettingsConfiguration>();
services.Configure<FacebookSettings, FacebookSettingsConfiguration>();

services.Configure<MvcOptions>((options) =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace OrchardCore.GitHub.Configuration;

public class GitHubAuthenticationSettingsConfiguration : IConfigureOptions<GitHubAuthenticationSettings>
public class GitHubAuthenticationSettingsConfiguration : IAsyncConfigureOptions<GitHubAuthenticationSettings>
{
private readonly IGitHubAuthenticationService _gitHubAuthenticationService;
private readonly ShellSettings _shellSettings;
Expand All @@ -25,11 +25,9 @@ public GitHubAuthenticationSettingsConfiguration(
_logger = logger;
}

public void Configure(GitHubAuthenticationSettings options)
public async ValueTask ConfigureAsync(GitHubAuthenticationSettings options)
{
var settings = GetGitHubAuthenticationSettingsAsync()
.GetAwaiter()
.GetResult();
var settings = await GetGitHubAuthenticationSettingsAsync();

if (settings != null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;

namespace OrchardCore.GitHub.Settings
{
public class GitHubAuthenticationSettings
public class GitHubAuthenticationSettings : IAsyncOptions
{
public string ClientID { get; set; }
public string ClientSecret { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/OrchardCore.Modules/OrchardCore.GitHub/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override void ConfigureServices(IServiceCollection services)
services.AddScoped<INavigationProvider, AdminMenuGitHubLogin>();
services.AddRecipeExecutionStep<GitHubAuthenticationSettingsStep>();

services.AddTransient<IConfigureOptions<GitHubAuthenticationSettings>, GitHubAuthenticationSettingsConfiguration>();
services.Configure<GitHubAuthenticationSettings, GitHubAuthenticationSettingsConfiguration>();

// Register the options initializers required by the GitHub Handler.
services.TryAddEnumerable(new[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace OrchardCore.Google.Authentication.Services;

public class GoogleAuthenticationSettingsConfiguration : IConfigureOptions<GoogleAuthenticationSettings>
public class GoogleAuthenticationSettingsConfiguration : IAsyncConfigureOptions<GoogleAuthenticationSettings>
{
private readonly GoogleAuthenticationService _googleAuthenticationService;
private readonly ShellSettings _shellSettings;
Expand All @@ -24,11 +24,9 @@ public GoogleAuthenticationSettingsConfiguration(
_logger = logger;
}

public void Configure(GoogleAuthenticationSettings options)
public async ValueTask ConfigureAsync(GoogleAuthenticationSettings options)
{
var settings = GetGoogleAuthenticationSettingsAsync()
.GetAwaiter()
.GetResult();
var settings = await GetGoogleAuthenticationSettingsAsync();

if (settings != null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;

namespace OrchardCore.Google.Authentication.Settings
{
public class GoogleAuthenticationSettings
public class GoogleAuthenticationSettings : IAsyncOptions
{
public string ClientID { get; set; }
public string ClientSecret { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public override void ConfigureServices(IServiceCollection services)
ServiceDescriptor.Transient<IPostConfigureOptions<GoogleOptions>, OAuthPostConfigureOptions<GoogleOptions,GoogleHandler>>()
});

services.AddTransient<IConfigureOptions<GoogleAuthenticationSettings>, GoogleAuthenticationSettingsConfiguration>();
services.Configure<GoogleAuthenticationSettings, GoogleAuthenticationSettingsConfiguration>();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.Extensions.Options;

namespace OrchardCore.Media.Processing
{
public class MediaTokenOptions
public class MediaTokenOptions : IAsyncOptions
{
public byte[] HashKey { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using OrchardCore.Settings;

namespace OrchardCore.Media.Processing
{
public class MediaTokenOptionsConfiguration : IConfigureOptions<MediaTokenOptions>
public class MediaTokenOptionsConfiguration : IAsyncConfigureOptions<MediaTokenOptions>
{
private readonly ISiteService _siteService;

Expand All @@ -12,10 +13,9 @@ public MediaTokenOptionsConfiguration(ISiteService siteService)
_siteService = siteService;
}

public void Configure(MediaTokenOptions options)
public async ValueTask ConfigureAsync(MediaTokenOptions options)
{
options.HashKey = _siteService.GetSiteSettingsAsync()
.GetAwaiter().GetResult()
options.HashKey = (await _siteService.GetSiteSettingsAsync())
.As<MediaTokenSettings>()
.HashKey;
}
Expand Down
2 changes: 1 addition & 1 deletion src/OrchardCore.Modules/OrchardCore.Media/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public override void ConfigureServices(IServiceCollection services)

services.AddScoped<MediaTokenSettingsUpdater>();
services.AddSingleton<IMediaTokenService, MediaTokenService>();
services.AddTransient<IConfigureOptions<MediaTokenOptions>, MediaTokenOptionsConfiguration>();
services.Configure<MediaTokenOptions, MediaTokenOptionsConfiguration>();
services.AddScoped<IFeatureEventHandler>(sp => sp.GetRequiredService<MediaTokenSettingsUpdater>());
services.AddScoped<IModularTenantEvents>(sp => sp.GetRequiredService<MediaTokenSettingsUpdater>());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace OrchardCore.Microsoft.Authentication.Configuration;

public class AzureADSettingsConfiguration : IConfigureOptions<AzureADSettings>
public class AzureADSettingsConfiguration : IAsyncConfigureOptions<AzureADSettings>
{
private readonly IAzureADService _azureADService;
private readonly ShellSettings _shellSettings;
Expand All @@ -25,11 +25,9 @@ public AzureADSettingsConfiguration(
_logger = logger;
}

public void Configure(AzureADSettings options)
public async ValueTask ConfigureAsync(AzureADSettings options)
{
var settings = GetAzureADSettingsAsync()
.GetAwaiter()
.GetResult();
var settings = await GetAzureADSettingsAsync();

if (settings != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace OrchardCore.Microsoft.Authentication.Configuration;

public class MicrosoftAccountSettingsConfiguration : IConfigureOptions<MicrosoftAccountSettings>
public class MicrosoftAccountSettingsConfiguration : IAsyncConfigureOptions<MicrosoftAccountSettings>
{
private readonly IMicrosoftAccountService _microsoftAccountService;
private readonly ShellSettings _shellSettings;
Expand All @@ -25,11 +25,9 @@ public MicrosoftAccountSettingsConfiguration(
_logger = logger;
}

public void Configure(MicrosoftAccountSettings options)
public async ValueTask ConfigureAsync(MicrosoftAccountSettings options)
{
var settings = GetMicrosoftAccountSettingsAsync()
.GetAwaiter()
.GetResult();
var settings = await GetMicrosoftAccountSettingsAsync();

if (settings != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public override void ConfigureServices(IServiceCollection services)
services.AddScoped<INavigationProvider, AdminMenuMicrosoftAccount>();
services.AddRecipeExecutionStep<MicrosoftAccountSettingsStep>();

services.AddTransient<IConfigureOptions<MicrosoftAccountSettings>, MicrosoftAccountSettingsConfiguration>();
services.Configure<MicrosoftAccountSettings, MicrosoftAccountSettingsConfiguration>();

// Register the options initializers required by the Microsoft Account Handler.
services.TryAddEnumerable(new[]
Expand All @@ -60,7 +60,7 @@ public override void ConfigureServices(IServiceCollection services)
services.AddScoped<IDisplayDriver<ISite>, AzureADSettingsDisplayDriver>();
services.AddScoped<INavigationProvider, AdminMenuAAD>();

services.AddTransient<IConfigureOptions<AzureADSettings>, AzureADSettingsConfiguration>();
services.Configure<AzureADSettings, AzureADSettingsConfiguration>();

// Register the options initializers required by the Policy Scheme, Cookie and OpenId Connect Handler.
services.TryAddEnumerable(new[]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;

namespace OrchardCore.Microsoft.Authentication.Settings
{
public class AzureADSettings
public class AzureADSettings : IAsyncOptions
{
public string DisplayName { get; set; }
public string AppId { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Options;

namespace OrchardCore.Microsoft.Authentication.Settings
{
public class MicrosoftAccountSettings
public class MicrosoftAccountSettings : IAsyncOptions
{
public string AppId { get; set; }
public string AppSecret { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.Extensions.Options;

namespace OrchardCore.Search.Models
{
public class SearchSettings
public class SearchSettings : IAsyncOptions
{
public string ProviderName { get; set; }

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using OrchardCore.Entities;
using OrchardCore.Search.Models;
using OrchardCore.Settings;

namespace OrchardCore.Search.Configuration
{
public class SearchSettingsConfiguration : IConfigureOptions<SearchSettings>
public class SearchSettingsConfiguration : IAsyncConfigureOptions<SearchSettings>
{
private readonly ISiteService _site;

Expand All @@ -14,11 +14,9 @@ public SearchSettingsConfiguration(ISiteService site)
_site = site;
}

public void Configure(SearchSettings options)
public async ValueTask ConfigureAsync(SearchSettings options)
{
var settings = _site.GetSiteSettingsAsync()
.GetAwaiter().GetResult()
.As<SearchSettings>();
var settings = (await _site.GetSiteSettingsAsync()).As<SearchSettings>();

options.ProviderName = settings.ProviderName;
}
Expand Down
2 changes: 1 addition & 1 deletion src/OrchardCore.Modules/OrchardCore.Search/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class Startup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddTransient<IConfigureOptions<SearchSettings>, SearchSettingsConfiguration>();
services.Configure<SearchSettings, SearchSettingsConfiguration>();
services.AddScoped<INavigationProvider, AdminMenu>();
services.AddScoped<IPermissionProvider, Permissions>();
services.AddScoped<IDisplayDriver<ISite>, SearchSettingsDisplayDriver>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using System.Threading.Tasks;
using Microsoft.Extensions.Options;
using OrchardCore.Security.Settings;

namespace OrchardCore.Security.Services
{
public class SecuritySettingsConfiguration : IConfigureOptions<SecuritySettings>
public class SecuritySettingsConfiguration : IAsyncConfigureOptions<SecuritySettings>
{
private readonly ISecurityService _securityService;

public SecuritySettingsConfiguration(ISecurityService securityService)
=> _securityService = securityService;

public void Configure(SecuritySettings options)
public async ValueTask ConfigureAsync(SecuritySettings options)
{
var securitySettings = _securityService.GetSettingsAsync()
.GetAwaiter().GetResult();
var securitySettings = await _securityService.GetSettingsAsync();

options.ContentSecurityPolicy = securitySettings.ContentSecurityPolicy;
options.ContentTypeOptions = securitySettings.ContentTypeOptions;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System.Collections.Generic;
using System.Linq;
using Microsoft.Extensions.Options;
using OrchardCore.Security.Options;

namespace OrchardCore.Security.Settings
{
public class SecuritySettings
public class SecuritySettings : IAsyncOptions
{
private Dictionary<string, string> _contentSecurityPolicy = new();
private Dictionary<string, string> _permissionsPolicy = new();
Expand Down
2 changes: 1 addition & 1 deletion src/OrchardCore.Modules/OrchardCore.Security/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public override void ConfigureServices(IServiceCollection services)

services.AddSingleton<ISecurityService, SecurityService>();

services.AddTransient<IConfigureOptions<SecuritySettings>, SecuritySettingsConfiguration>();
services.Configure<SecuritySettings, SecuritySettingsConfiguration>();
}

public override void Configure(IApplicationBuilder builder, IEndpointRouteBuilder routes, IServiceProvider serviceProvider)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace OrchardCore.Twitter.Services;

public class TwitterSettingsConfiguration : IConfigureOptions<TwitterSettings>
public class TwitterSettingsConfiguration : IAsyncConfigureOptions<TwitterSettings>
{
private readonly ITwitterSettingsService _twitterSettingsService;
private readonly ShellSettings _shellSettings;
Expand All @@ -24,11 +24,9 @@ public TwitterSettingsConfiguration(
_logger = logger;
}

public void Configure(TwitterSettings options)
public async ValueTask ConfigureAsync(TwitterSettings options)
{
var settings = GetTwitterSettingsAsync()
.GetAwaiter()
.GetResult();
var settings = await GetTwitterSettingsAsync();

if (settings != null)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using Microsoft.Extensions.Options;

namespace OrchardCore.Twitter.Settings
{
public class TwitterSettings
public class TwitterSettings : IAsyncOptions
{
public string ConsumerKey { get; set; }
public string ConsumerSecret { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion src/OrchardCore.Modules/OrchardCore.Twitter/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public override void ConfigureServices(IServiceCollection services)
services.AddRecipeExecutionStep<TwitterSettingsStep>();

services.AddTransient<TwitterClientMessageHandler>();
services.AddTransient<IConfigureOptions<TwitterSettings>, TwitterSettingsConfiguration>();
services.Configure<TwitterSettings, TwitterSettingsConfiguration>();

services.AddHttpClient<TwitterClient>()
.AddHttpMessageHandler<TwitterClientMessageHandler>()
Expand Down
Loading
Loading