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

Algolia Installer work around to solve problem where Application is n… #33

Merged
merged 2 commits into from
Feb 13, 2024
Merged
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
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
Loading