From 0b4aee0bed6afb88e49f42d56f3631b433a483db Mon Sep 17 00:00:00 2001 From: hafidis Date: Tue, 2 Jul 2024 16:31:03 +0200 Subject: [PATCH] admin module initialize the service --- Directory.Build.props | 2 +- .../Admin/TypesenseAdminModule.cs | 8 ++++++++ .../TypesenseAdminStartupExtensions.cs | 2 +- examples/DancingGoat/Program.cs | 3 +-- .../Search/DancingGoatSearchStartupExtensions.cs | 10 ---------- 5 files changed, 11 insertions(+), 14 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 35e0d00..0458158 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -5,7 +5,7 @@ $(Company) Copyright © $(Company) $([System.DateTime]::Now.Year) $(Company)™ - 1.0.0-beta-1 + 1.0.1-beta-1 MIT diff --git a/Kentico.Xperience.Typesense.Admin/Admin/TypesenseAdminModule.cs b/Kentico.Xperience.Typesense.Admin/Admin/TypesenseAdminModule.cs index db1d57a..bdd528f 100644 --- a/Kentico.Xperience.Typesense.Admin/Admin/TypesenseAdminModule.cs +++ b/Kentico.Xperience.Typesense.Admin/Admin/TypesenseAdminModule.cs @@ -6,6 +6,7 @@ using Kentico.Xperience.Typesense.Collection; using Kentico.Xperience.Typesense.Xperience; +using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; @@ -46,5 +47,12 @@ protected override void OnInit(ModuleInitParameters parameters) ApplicationEvents.PostStart.Execute += InitializeModule; } + protected override void OnPreInit(ModulePreInitParameters parameters) + { + PreInit(parameters); + var services = parameters.Services; + services.AddKenticoAdminTypesense(); + } + private void InitializeModule(object? sender, EventArgs e) => TypesenseCollectionStore.SetIndicies(storageService); } diff --git a/Kentico.Xperience.Typesense.Admin/TypesenseAdminStartupExtensions.cs b/Kentico.Xperience.Typesense.Admin/TypesenseAdminStartupExtensions.cs index dc4de0f..9c4b0f6 100644 --- a/Kentico.Xperience.Typesense.Admin/TypesenseAdminStartupExtensions.cs +++ b/Kentico.Xperience.Typesense.Admin/TypesenseAdminStartupExtensions.cs @@ -23,7 +23,7 @@ public static class TypesenseAdminStartupExtensions /// /// The application configuration. /// - public static IServiceCollection AddKenticoAdminTypesense(this IServiceCollection serviceCollection, Action configure, IConfiguration configuration) => + public static IServiceCollection AddKenticoAdminTypesense(this IServiceCollection serviceCollection) => serviceCollection .AddSingleton() .AddSingleton() diff --git a/examples/DancingGoat/Program.cs b/examples/DancingGoat/Program.cs index e3f3b95..84b6721 100644 --- a/examples/DancingGoat/Program.cs +++ b/examples/DancingGoat/Program.cs @@ -56,8 +56,7 @@ builder.Services.AddDancingGoatServices(); builder.Services - .AddKenticoTypesenseServices(builder.Configuration) - .AddKenticoAdminTypesenseServices(builder.Configuration); //Only add this line if you are using the Kentico Admin only one app is suppose to do the dequeuing. + .AddKenticoTypesenseServices(builder.Configuration); ConfigureMembershipServices(builder.Services); diff --git a/examples/DancingGoat/Search/DancingGoatSearchStartupExtensions.cs b/examples/DancingGoat/Search/DancingGoatSearchStartupExtensions.cs index 3982fd0..31f6895 100644 --- a/examples/DancingGoat/Search/DancingGoatSearchStartupExtensions.cs +++ b/examples/DancingGoat/Search/DancingGoatSearchStartupExtensions.cs @@ -22,14 +22,4 @@ public static IServiceCollection AddKenticoTypesenseServices(this IServiceCollec return services; } - - public static IServiceCollection AddKenticoAdminTypesenseServices(this IServiceCollection services, IConfiguration configuration) - { - services.AddKenticoAdminTypesense(builder => - { - }, configuration); - - return services; - } } -