Skip to content

Commit

Permalink
Merge pull request #33 from Kentico/fix/moduleInstaller
Browse files Browse the repository at this point in the history
Algolia Installer work around to solve problem where Application is n…
  • Loading branch information
ondrejhenek authored Feb 13, 2024
2 parents afff8e0 + 9329d82 commit f1b8cd7
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
3 changes: 1 addition & 2 deletions src/Kentico.Xperience.Algolia/Admin/AlgoliaAdminModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@ public AlgoliaAdminModule() : base(nameof(AlgoliaAdminModule)) { }
protected override void OnInit(ModuleInitParameters parameters)
{
base.OnInit(parameters);

RegisterClientModule("kentico", "xperience-integrations-algolia");

var services = parameters.Services;

installer = services.GetRequiredService<AlgoliaModuleInstaller>();
storageService = services.GetRequiredService<IAlgoliaConfigurationStorageService>();

ApplicationEvents.Initialized.Execute += InitializeModule;
ApplicationEvents.PostStart.Execute += InitializeModule;
}

private void InitializeModule(object? sender, EventArgs e)
Expand Down
9 changes: 4 additions & 5 deletions src/Kentico.Xperience.Algolia/AlgoliaSearchModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ public AlgoliaSearchModule() : base(nameof(AlgoliaSearchModule))
protected override void OnInit(ModuleInitParameters parameters)
{
base.OnInit();

var services = parameters.Services;

services.GetRequiredService<AlgoliaModuleInstaller>().Install();
algoliaTaskLogger = Service.Resolve<IAlgoliaTaskLogger>();
appSettingsService = Service.Resolve<IAppSettingsService>();
conversionService = Service.Resolve<IConversionService>();
algoliaTaskLogger = services.GetRequiredService<IAlgoliaTaskLogger>();
appSettingsService = services.GetRequiredService<IAppSettingsService>();
conversionService = services.GetRequiredService<IConversionService>();


AddRegisteredIndices();
WebPageEvents.Publish.Execute += HandleEvent;
WebPageEvents.Delete.Execute += HandleEvent;
ContentItemEvents.Publish.Execute += HandleContentItemEvent;
Expand Down
22 changes: 20 additions & 2 deletions src/Kentico.Xperience.Algolia/AlgoliaStartupExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static class AlgoliaStartupExtensions
/// </summary>
/// <param name="services">The service collection.</param>
/// <param name="configuration">The application configuration.</param>
public static IServiceCollection AddKenticoAlgolia(this IServiceCollection services, IConfiguration configuration) =>
private static IServiceCollection AddKenticoAlgoliaInternal(this IServiceCollection services, IConfiguration configuration) =>
services.AddSingleton<AlgoliaModuleInstaller>()
.Configure<AlgoliaOptions>(configuration.GetSection(AlgoliaOptions.CMS_ALGOLIA_SECTION_NAME))
.AddSingleton<IInsightsClient>(s =>
Expand Down Expand Up @@ -53,7 +53,7 @@ public static IServiceCollection AddKenticoAlgolia(this IServiceCollection servi
/// <returns></returns>
public static IServiceCollection AddKenticoAlgolia(this IServiceCollection serviceCollection, Action<IAlgoliaBuilder> configure, IConfiguration configuration)
{
serviceCollection.AddKenticoAlgolia(configuration);
serviceCollection.AddKenticoAlgoliaInternal(configuration);

var builder = new AlgoliaBuilder(serviceCollection);

Expand All @@ -67,6 +67,24 @@ public static IServiceCollection AddKenticoAlgolia(this IServiceCollection servi

return serviceCollection;
}

/// <summary>
/// Adds Algolia services and custom module to application with <see cref="DefaultAlgoliaIndexingStrategy"/>
/// </summary>
/// <param name="serviceCollection"></param>
/// <param name="configuration">The application configuration.</param>
/// <returns></returns>
public static IServiceCollection AddKenticoAlgolia(this IServiceCollection serviceCollection, IConfiguration configuration)
{
serviceCollection.AddKenticoAlgoliaInternal(configuration);

var builder = new AlgoliaBuilder(serviceCollection);

serviceCollection.AddTransient<DefaultAlgoliaIndexingStrategy>();
builder.RegisterStrategy<DefaultAlgoliaIndexingStrategy>("Default");

return serviceCollection;
}
}


Expand Down

0 comments on commit f1b8cd7

Please sign in to comment.