Skip to content

Commit

Permalink
Add AddIndexProvider and AddScopedIndexProvider extensions (#13060)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek committed Jan 13, 2023
1 parent 92f3bd1 commit af2c2bb
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 49 deletions.
6 changes: 3 additions & 3 deletions src/OrchardCore.Modules/OrchardCore.AdminDashboard/Startup.cs
Expand Up @@ -11,11 +11,11 @@
using OrchardCore.AdminDashboard.Services;
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Display.ContentDisplay;
using OrchardCore.Data;
using OrchardCore.Data.Migration;
using OrchardCore.Modules;
using OrchardCore.Mvc.Core.Utilities;
using OrchardCore.Security.Permissions;
using YesSql.Indexes;

namespace OrchardCore.AdminDashboard
{
Expand All @@ -35,7 +35,7 @@ public override void ConfigureServices(IServiceCollection services)
services.AddScoped<IPermissionProvider, Permissions>();

services.AddScoped<IAdminDashboardService, AdminDashboardService>();
services.AddSingleton<IIndexProvider, DashboardPartIndexProvider>();
services.AddIndexProvider<DashboardPartIndexProvider>();

services.AddContentPart<DashboardPart>()
.UseDisplayDriver<DashboardPartDisplayDriver>();
Expand All @@ -60,7 +60,7 @@ public override void Configure(IApplicationBuilder builder, IEndpointRouteBuilde
routes.MapAreaControllerRoute(
name: "AdminDashboard",
areaName: "OrchardCore.AdminDashboard",
pattern: $"{ _adminOptions.AdminUrlPrefix }/dashboard/manage",
pattern: $"{_adminOptions.AdminUrlPrefix}/dashboard/manage",
defaults: new { controller = dashboardControllerName, action = nameof(DashboardController.Manage) }
);
}
Expand Down
4 changes: 1 addition & 3 deletions src/OrchardCore.Modules/OrchardCore.AuditTrail/Startup.cs
Expand Up @@ -19,7 +19,6 @@
using OrchardCore.BackgroundTasks;
using OrchardCore.Data;
using OrchardCore.Data.Migration;
using OrchardCore.DisplayManagement;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.Modules;
using OrchardCore.Mvc.Core.Utilities;
Expand All @@ -28,7 +27,6 @@
using OrchardCore.Settings;
using OrchardCore.Settings.Deployment;
using YesSql.Filters.Query;
using YesSql.Indexes;

namespace OrchardCore.AuditTrail
{
Expand Down Expand Up @@ -56,7 +54,7 @@ public override void ConfigureServices(IServiceCollection services)
services.Configure<StoreCollectionOptions>(o => o.Collections.Add(AuditTrailEvent.Collection));

services.AddDataMigration<Migrations>();
services.AddSingleton<IIndexProvider, AuditTrailEventIndexProvider>();
services.AddIndexProvider<AuditTrailEventIndexProvider>();
services.AddSingleton<IBackgroundTask, AuditTrailBackgroundTask>();

services.AddScoped<IPermissionProvider, Permissions>();
Expand Down
24 changes: 12 additions & 12 deletions src/OrchardCore.Modules/OrchardCore.ContentFields/Startup.cs
Expand Up @@ -203,16 +203,16 @@ public class IndexingStartup : StartupBase
public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IDataMigration, Indexing.SQL.Migrations>();
services.AddScoped<IScopedIndexProvider, TextFieldIndexProvider>();
services.AddScoped<IScopedIndexProvider, BooleanFieldIndexProvider>();
services.AddScoped<IScopedIndexProvider, NumericFieldIndexProvider>();
services.AddScoped<IScopedIndexProvider, DateTimeFieldIndexProvider>();
services.AddScoped<IScopedIndexProvider, DateFieldIndexProvider>();
services.AddScoped<IScopedIndexProvider, ContentPickerFieldIndexProvider>();
services.AddScoped<IScopedIndexProvider, TimeFieldIndexProvider>();
services.AddScoped<IScopedIndexProvider, LinkFieldIndexProvider>();
services.AddScoped<IScopedIndexProvider, HtmlFieldIndexProvider>();
services.AddScoped<IScopedIndexProvider, MultiTextFieldIndexProvider>();
services.AddScopedIndexProvider<TextFieldIndexProvider>();
services.AddScopedIndexProvider<BooleanFieldIndexProvider>();
services.AddScopedIndexProvider<NumericFieldIndexProvider>();
services.AddScopedIndexProvider<DateTimeFieldIndexProvider>();
services.AddScopedIndexProvider<DateFieldIndexProvider>();
services.AddScopedIndexProvider<ContentPickerFieldIndexProvider>();
services.AddScopedIndexProvider<TimeFieldIndexProvider>();
services.AddScopedIndexProvider<LinkFieldIndexProvider>();
services.AddScopedIndexProvider<HtmlFieldIndexProvider>();
services.AddScopedIndexProvider<MultiTextFieldIndexProvider>();
}
}

Expand Down Expand Up @@ -261,8 +261,8 @@ public class UserPickerSqlIndexingStartup : StartupBase
{
public override void ConfigureServices(IServiceCollection services)
{
services.AddScoped<IDataMigration, Indexing.SQL.UserPickerMigrations>();
services.AddScoped<IScopedIndexProvider, UserPickerFieldIndexProvider>();
services.AddScoped<IDataMigration, UserPickerMigrations>();
services.AddScopedIndexProvider<UserPickerFieldIndexProvider>();
}
}
}
5 changes: 2 additions & 3 deletions src/OrchardCore.Modules/OrchardCore.Deployment/Startup.cs
Expand Up @@ -4,21 +4,20 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using OrchardCore.Admin;
using OrchardCore.Data;
using OrchardCore.Data.Migration;
using OrchardCore.Deployment.Controllers;
using OrchardCore.Deployment.Core;
using OrchardCore.Deployment.Deployment;
using OrchardCore.Deployment.Indexes;
using OrchardCore.Deployment.Recipes;
using OrchardCore.Deployment.Steps;
using OrchardCore.DisplayManagement;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.Modules;
using OrchardCore.Mvc.Core.Utilities;
using OrchardCore.Navigation;
using OrchardCore.Recipes;
using OrchardCore.Security.Permissions;
using YesSql.Indexes;

namespace OrchardCore.Deployment
{
Expand Down Expand Up @@ -49,7 +48,7 @@ public override void ConfigureServices(IServiceCollection services)
services.AddSingleton<IDeploymentStepFactory>(new DeploymentStepFactory<RecipeFileDeploymentStep>());
services.AddScoped<IDisplayDriver<DeploymentStep>, RecipeFileDeploymentStepDriver>();

services.AddSingleton<IIndexProvider, DeploymentPlanIndexProvider>();
services.AddIndexProvider<DeploymentPlanIndexProvider>();
services.AddTransient<IDataMigration, Migrations>();

services.AddScoped<IDeploymentPlanService, DeploymentPlanService>();
Expand Down
4 changes: 2 additions & 2 deletions src/OrchardCore.Modules/OrchardCore.Layers/Startup.cs
Expand Up @@ -9,6 +9,7 @@
using OrchardCore.ContentManagement;
using OrchardCore.ContentManagement.Display.ContentDisplay;
using OrchardCore.ContentManagement.Handlers;
using OrchardCore.Data;
using OrchardCore.Data.Migration;
using OrchardCore.Deployment;
using OrchardCore.DisplayManagement.Handlers;
Expand All @@ -28,7 +29,6 @@
using OrchardCore.Scripting;
using OrchardCore.Security.Permissions;
using OrchardCore.Settings;
using YesSql.Indexes;

namespace OrchardCore.Layers
{
Expand Down Expand Up @@ -59,7 +59,7 @@ public override void ConfigureServices(IServiceCollection services)
services.AddScoped<INavigationProvider, AdminMenu>();
services.AddScoped<ILayerService, LayerService>();
services.AddScoped<IContentHandler, LayerMetadataHandler>();
services.AddSingleton<IIndexProvider, LayerMetadataIndexProvider>();
services.AddIndexProvider<LayerMetadataIndexProvider>();
services.AddDataMigration<Migrations>();
services.AddScoped<IPermissionProvider, Permissions>();
services.AddRecipeExecutionStep<LayerStep>();
Expand Down
4 changes: 2 additions & 2 deletions src/OrchardCore.Modules/OrchardCore.Lists/Startup.cs
Expand Up @@ -14,6 +14,7 @@
using OrchardCore.Contents.Services;
using OrchardCore.Contents.ViewModels;
using OrchardCore.ContentTypes.Editors;
using OrchardCore.Data;
using OrchardCore.Data.Migration;
using OrchardCore.DisplayManagement.Handlers;
using OrchardCore.Feeds;
Expand All @@ -31,7 +32,6 @@
using OrchardCore.Lists.ViewModels;
using OrchardCore.Modules;
using OrchardCore.Navigation;
using YesSql.Indexes;

namespace OrchardCore.Lists
{
Expand All @@ -55,7 +55,7 @@ public override void ConfigureServices(IServiceCollection services)
.AddLiquidFilter<ListItemsFilter>("list_items")
.AddLiquidFilter<ContainerFilter>("container");

services.AddSingleton<IIndexProvider, ContainedPartIndexProvider>();
services.AddIndexProvider<ContainedPartIndexProvider>();
services.AddScoped<IContentDisplayDriver, ContainedPartDisplayDriver>();
services.AddScoped<IContentHandler, ContainedPartHandler>();
services.AddContentPart<ContainedPart>();
Expand Down
3 changes: 1 addition & 2 deletions src/OrchardCore.Modules/OrchardCore.Notifications/Startup.cs
Expand Up @@ -25,7 +25,6 @@
using OrchardCore.Users.Models;
using OrchardCore.Workflows.Helpers;
using YesSql.Filters.Query;
using YesSql.Indexes;

namespace OrchardCore.Notifications;

Expand All @@ -44,7 +43,7 @@ public override void ConfigureServices(IServiceCollection services)
services.AddScoped<INotificationMethodProviderAccessor, NotificationMethodProviderAccessor>();

services.AddDataMigration<NotificationMigrations>();
services.AddSingleton<IIndexProvider, NotificationIndexProvider>();
services.AddIndexProvider<NotificationIndexProvider>();
services.AddScoped<INotificationsAdminListQueryService, DefaultNotificationsAdminListQueryService>();
services.Configure<StoreCollectionOptions>(o => o.Collections.Add(NotificationConstants.NotificationCollection));
services.AddScoped<INotificationEvents, CoreNotificationEventsHandler>();
Expand Down
2 changes: 1 addition & 1 deletion src/OrchardCore.Modules/OrchardCore.Taxonomies/Startup.cs
Expand Up @@ -82,7 +82,7 @@ public override void ConfigureServices(IServiceCollection services)

services.AddScoped<IContentPartFieldDefinitionDisplayDriver, TaxonomyFieldTagsEditorSettingsDriver>();

services.AddScoped<IScopedIndexProvider, TaxonomyIndexProvider>();
services.AddScopedIndexProvider<TaxonomyIndexProvider>();

// Terms.
services.AddContentPart<TermPart>();
Expand Down
6 changes: 3 additions & 3 deletions src/OrchardCore.Modules/OrchardCore.Workflows/Startup.cs
Expand Up @@ -5,6 +5,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;
using OrchardCore.Admin;
using OrchardCore.Data;
using OrchardCore.Data.Migration;
using OrchardCore.Deployment;
using OrchardCore.DisplayManagement.Handlers;
Expand All @@ -27,7 +28,6 @@
using OrchardCore.Workflows.Recipes;
using OrchardCore.Workflows.Services;
using OrchardCore.Workflows.WorkflowContextProviders;
using YesSql.Indexes;

namespace OrchardCore.Workflows
{
Expand Down Expand Up @@ -65,8 +65,8 @@ public override void ConfigureServices(IServiceCollection services)
services.AddScoped<INavigationProvider, AdminMenu>();
services.AddScoped<IPermissionProvider, Permissions>();
services.AddScoped<IDisplayDriver<IActivity>, MissingActivityDisplayDriver>();
services.AddSingleton<IIndexProvider, WorkflowTypeIndexProvider>();
services.AddSingleton<IIndexProvider, WorkflowIndexProvider>();
services.AddIndexProvider<WorkflowTypeIndexProvider>();
services.AddIndexProvider<WorkflowIndexProvider>();
services.AddScoped<IWorkflowExecutionContextHandler, DefaultWorkflowExecutionContextHandler>();
services.AddScoped<IWorkflowExpressionEvaluator, LiquidWorkflowExpressionEvaluator>();
services.AddScoped<IWorkflowScriptEvaluator, JavaScriptWorkflowScriptEvaluator>();
Expand Down
Expand Up @@ -4,9 +4,9 @@
using OrchardCore.ContentManagement.Handlers;
using OrchardCore.ContentManagement.Metadata;
using OrchardCore.ContentManagement.Records;
using OrchardCore.Data;
using OrchardCore.Data.Migration;
using OrchardCore.Environment.Cache;
using YesSql.Indexes;

namespace OrchardCore.ContentManagement
{
Expand All @@ -19,7 +19,7 @@ public static IServiceCollection AddContentManagement(this IServiceCollection se
services.TryAddScoped<IContentDefinitionStore, DatabaseContentDefinitionStore>();
services.TryAddScoped<IContentManager, DefaultContentManager>();
services.TryAddScoped<IContentManagerSession, DefaultContentManagerSession>();
services.AddSingleton<IIndexProvider, ContentItemIndexProvider>();
services.AddIndexProvider<ContentItemIndexProvider>();
services.AddDataMigration<Migrations>();
services.AddScoped<IContentHandler, UpdateContentsHandler>();
services.AddScoped<IContentHandler, ContentPartHandlerCoordinator>();
Expand Down
@@ -0,0 +1,19 @@
using Microsoft.Extensions.DependencyInjection;
using YesSql.Indexes;

namespace OrchardCore.Data;

public static class IndexServiceCollectionExtensions
{
public static IServiceCollection AddIndexProvider<TIndexProvider>(this IServiceCollection services)
where TIndexProvider : class, IIndexProvider
{
return services.AddSingleton<IIndexProvider, TIndexProvider>();
}

public static IServiceCollection AddScopedIndexProvider<TScopedIndexProvider>(this IServiceCollection services)
where TScopedIndexProvider : class, IScopedIndexProvider
{
return services.AddScoped<IScopedIndexProvider, TScopedIndexProvider>();
}
}
Expand Up @@ -5,7 +5,7 @@ namespace OrchardCore.Data.Migration;
/// <summary>
/// Provides extension methods for <see cref="IServiceCollection"/> to add YesSql migration <see cref="IDataMigration"/>.
/// </summary>
public static class ServiceCollectionExtensions
public static class MigrationServiceCollectionExtensions
{
public static IServiceCollection AddDataMigration<TDataMigration>(this IServiceCollection services)
where TDataMigration : class, IDataMigration
Expand Down
@@ -1,13 +1,13 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.DependencyInjection.Extensions;
using OrchardCore.Data;
using OrchardCore.Roles.Services;
using OrchardCore.Security;
using OrchardCore.Security.Services;
using OrchardCore.Users;
using OrchardCore.Users.Handlers;
using OrchardCore.Users.Indexes;
using OrchardCore.Users.Services;
using YesSql.Indexes;

namespace Microsoft.Extensions.DependencyInjection
{
Expand Down Expand Up @@ -36,10 +36,13 @@ public static IServiceCollection AddUsers(this IServiceCollection services)
services.TryAddScoped<IRoleClaimStore<IRole>>(sp => sp.GetRequiredService<NullRoleStore>());
services.TryAddScoped<IRoleStore<IRole>>(sp => sp.GetRequiredService<NullRoleStore>());

services.AddSingleton<IIndexProvider, UserIndexProvider>();
services.AddSingleton<IIndexProvider, UserByRoleNameIndexProvider>();
services.AddSingleton<IIndexProvider, UserByLoginInfoIndexProvider>();
services.AddSingleton<IIndexProvider, UserByClaimIndexProvider>();
services.TryAddScoped<RoleManager<IRole>>();
services.TryAddScoped<IRoleService, RoleService>();

services.AddIndexProvider<UserIndexProvider>();
services.AddIndexProvider<UserByRoleNameIndexProvider>();
services.AddIndexProvider<UserByLoginInfoIndexProvider>();
services.AddIndexProvider<UserByClaimIndexProvider>();

services.AddScoped<IUserService, UserService>();
services.AddScoped<IUserClaimsPrincipalFactory<IUser>, DefaultUserClaimsPrincipalProviderFactory>();
Expand Down
21 changes: 11 additions & 10 deletions test/OrchardCore.Tests/Apis/GraphQL/ContentItemsFieldTypeTests.cs
Expand Up @@ -8,6 +8,7 @@
using OrchardCore.ContentManagement.GraphQL.Options;
using OrchardCore.ContentManagement.GraphQL.Queries;
using OrchardCore.ContentManagement.Records;
using OrchardCore.Data;
using OrchardCore.Environment.Shell;
using YesSql;
using YesSql.Indexes;
Expand Down Expand Up @@ -195,7 +196,7 @@ public async Task ShouldFilterByAliasIndexRegardlessOfInputFieldCase(string fiel
services.Populate(new ServiceCollection());
services.Services.AddScoped(x => _store.CreateSession());
services.Services.AddScoped(x => new ShellSettings());
services.Services.AddScoped<IIndexProvider, AnimalIndexProvider>();
services.Services.AddIndexProvider<AnimalIndexProvider>();
services.Services.AddScoped<IIndexAliasProvider, MultipleAliasIndexProvider>();
services.Services.AddSingleton<IIndexPropertyProvider, IndexPropertyProvider<AnimalIndex>>();
services.Build();
Expand Down Expand Up @@ -229,8 +230,8 @@ public async Task ShouldBeAbleToUseTheSameIndexForMultipleAliases()
services.Populate(new ServiceCollection());
services.Services.AddScoped(x => new ShellSettings());
services.Services.AddScoped(x => _store.CreateSession());
services.Services.AddScoped<IIndexProvider, ContentItemIndexProvider>();
services.Services.AddScoped<IIndexProvider, AnimalIndexProvider>();
services.Services.AddIndexProvider<ContentItemIndexProvider>();
services.Services.AddIndexProvider<AnimalIndexProvider>();
services.Services.AddScoped<IIndexAliasProvider, MultipleAliasIndexProvider>();
services.Services.AddSingleton<IIndexPropertyProvider, IndexPropertyProvider<AnimalIndex>>();

Expand Down Expand Up @@ -271,9 +272,9 @@ public async Task ShouldFilterOnMultipleIndexesOnSameAlias()
services.Populate(new ServiceCollection());
services.Services.AddScoped(x => new ShellSettings());
services.Services.AddScoped(x => _store.CreateSession());
services.Services.AddScoped<IIndexProvider, ContentItemIndexProvider>();
services.Services.AddScoped<IIndexProvider, AnimalIndexProvider>();
services.Services.AddScoped<IIndexProvider, AnimalTraitsIndexProvider>();
services.Services.AddIndexProvider<ContentItemIndexProvider>();
services.Services.AddIndexProvider<AnimalIndexProvider>();
services.Services.AddIndexProvider<AnimalTraitsIndexProvider>();
services.Services.AddScoped<IIndexAliasProvider, MultipleIndexesIndexProvider>();

services.Services.AddSingleton<IIndexPropertyProvider, IndexPropertyProvider<AnimalIndex>>();
Expand Down Expand Up @@ -319,8 +320,8 @@ public async Task ShouldFilterPartsWithoutAPrefixWhenThePartHasNoPrefix()
services.Populate(new ServiceCollection());
services.Services.AddScoped(x => _store.CreateSession());
services.Services.AddScoped(x => new ShellSettings());
services.Services.AddScoped<IIndexProvider, ContentItemIndexProvider>();
services.Services.AddScoped<IIndexProvider, AnimalIndexProvider>();
services.Services.AddIndexProvider<ContentItemIndexProvider>();
services.Services.AddIndexProvider<AnimalIndexProvider>();
services.Services.AddScoped<IIndexAliasProvider, MultipleAliasIndexProvider>();
services.Services.AddSingleton<IIndexPropertyProvider, IndexPropertyProvider<AnimalIndex>>();
services.Build();
Expand Down Expand Up @@ -354,8 +355,8 @@ public async Task ShouldFilterByCollapsedWhereInputForCollapsedParts()
services.Populate(new ServiceCollection());
services.Services.AddScoped(x => new ShellSettings());
services.Services.AddScoped(x => _store.CreateSession());
services.Services.AddScoped<IIndexProvider, ContentItemIndexProvider>();
services.Services.AddScoped<IIndexProvider, AnimalIndexProvider>();
services.Services.AddIndexProvider<ContentItemIndexProvider>();
services.Services.AddIndexProvider<AnimalIndexProvider>();
services.Services.AddScoped<IIndexAliasProvider, MultipleAliasIndexProvider>();
services.Services.AddSingleton<IIndexPropertyProvider, IndexPropertyProvider<AnimalIndex>>();
services.Build();
Expand Down

0 comments on commit af2c2bb

Please sign in to comment.