diff --git a/src/Kentico.Xperience.Algolia/Admin/AlgoliaAdminModule.cs b/src/Kentico.Xperience.Algolia/Admin/AlgoliaAdminModule.cs index eb04a77..c2a16d0 100644 --- a/src/Kentico.Xperience.Algolia/Admin/AlgoliaAdminModule.cs +++ b/src/Kentico.Xperience.Algolia/Admin/AlgoliaAdminModule.cs @@ -23,7 +23,6 @@ public AlgoliaAdminModule() : base(nameof(AlgoliaAdminModule)) { } protected override void OnInit(ModuleInitParameters parameters) { base.OnInit(parameters); - RegisterClientModule("kentico", "xperience-integrations-algolia"); var services = parameters.Services; @@ -31,7 +30,7 @@ protected override void OnInit(ModuleInitParameters parameters) installer = services.GetRequiredService(); storageService = services.GetRequiredService(); - ApplicationEvents.Initialized.Execute += InitializeModule; + ApplicationEvents.PostStart.Execute += InitializeModule; } private void InitializeModule(object? sender, EventArgs e) diff --git a/src/Kentico.Xperience.Algolia/AlgoliaSearchModule.cs b/src/Kentico.Xperience.Algolia/AlgoliaSearchModule.cs index 3c8dbe4..15c9ea9 100644 --- a/src/Kentico.Xperience.Algolia/AlgoliaSearchModule.cs +++ b/src/Kentico.Xperience.Algolia/AlgoliaSearchModule.cs @@ -34,15 +34,14 @@ public AlgoliaSearchModule() : base(nameof(AlgoliaSearchModule)) protected override void OnInit(ModuleInitParameters parameters) { base.OnInit(); + var services = parameters.Services; - services.GetRequiredService().Install(); - algoliaTaskLogger = Service.Resolve(); - appSettingsService = Service.Resolve(); - conversionService = Service.Resolve(); + algoliaTaskLogger = services.GetRequiredService(); + appSettingsService = services.GetRequiredService(); + conversionService = services.GetRequiredService(); - AddRegisteredIndices(); WebPageEvents.Publish.Execute += HandleEvent; WebPageEvents.Delete.Execute += HandleEvent; ContentItemEvents.Publish.Execute += HandleContentItemEvent; diff --git a/src/Kentico.Xperience.Algolia/AlgoliaStartupExtensions.cs b/src/Kentico.Xperience.Algolia/AlgoliaStartupExtensions.cs index 974c355..678dde7 100644 --- a/src/Kentico.Xperience.Algolia/AlgoliaStartupExtensions.cs +++ b/src/Kentico.Xperience.Algolia/AlgoliaStartupExtensions.cs @@ -18,7 +18,7 @@ public static class AlgoliaStartupExtensions /// /// The service collection. /// The application configuration. - public static IServiceCollection AddKenticoAlgolia(this IServiceCollection services, IConfiguration configuration) => + private static IServiceCollection AddKenticoAlgoliaInternal(this IServiceCollection services, IConfiguration configuration) => services.AddSingleton() .Configure(configuration.GetSection(AlgoliaOptions.CMS_ALGOLIA_SECTION_NAME)) .AddSingleton(s => @@ -53,7 +53,7 @@ public static IServiceCollection AddKenticoAlgolia(this IServiceCollection servi /// public static IServiceCollection AddKenticoAlgolia(this IServiceCollection serviceCollection, Action configure, IConfiguration configuration) { - serviceCollection.AddKenticoAlgolia(configuration); + serviceCollection.AddKenticoAlgoliaInternal(configuration); var builder = new AlgoliaBuilder(serviceCollection); @@ -67,6 +67,24 @@ public static IServiceCollection AddKenticoAlgolia(this IServiceCollection servi return serviceCollection; } + + /// + /// Adds Algolia services and custom module to application with + /// + /// + /// The application configuration. + /// + public static IServiceCollection AddKenticoAlgolia(this IServiceCollection serviceCollection, IConfiguration configuration) + { + serviceCollection.AddKenticoAlgoliaInternal(configuration); + + var builder = new AlgoliaBuilder(serviceCollection); + + serviceCollection.AddTransient(); + builder.RegisterStrategy("Default"); + + return serviceCollection; + } }