Replies: 1 comment 2 replies
-
@bmedwards Hey Brian! You'll want to have a custom using CMS;
using CMS.Core;
using CMS.DataEngine;
using CMSApp.Configuration;
using Kentico.Xperience.AlgoliaSearch.Services;
[assembly: RegisterModule(typeof(DependencyManagementModule))]
namespace CMSApp.Configuration
{
public class DependencyManagementModule : Module
{
public DependencyManagementModule() : base(nameof(DependencyManagementModule)) { }
protected override void OnPreInit()
{
base.OnPreInit();
// See: https://github.com/Kentico/xperience-algolia#gear-creating-and-registering-an-algolia-index
string indexName = "..."; // populate this however you want
// AlgoliaCustomSearchModel is your custom class that inherits from AlgoliaSearchModel
IAlgoliaIndexRegister register = new DefaultAlgoliaIndexRegister().Add<AlgoliaCustomSearchModel>(indexName);
Service.Use<IAlgoliaIndexRegister>(register);
}
protected override void OnInit()
{
base.OnInit();
//
}
}
} This I typically use it as the single location where all custom dependencies and modules are registered that I want the CMS application to use. On the ASPNET Core application side, you'll have some customization to the public static class ServiceCollectionXperienceExtensions
{
public static IServiceCollection AddXperienceAlgolia(this IServiceCollection services, IConfiguration config)
{
var algoliaSection = config.GetSection(AlgoliaOptions.SECTION_NAME);
string indexName = "..."; // get this however you want
// This is the same thing we did in the DependencyManagementModule in the CMSApp project
var register = new DefaultAlgoliaIndexRegister().Add<AlgoliaSiteSearchModel>(indexName);
return services
.AddAlgolia(config, register)
.Configure<AlgoliaOptions>(options =>
{
var algoliaOptions = algoliaSection.Get<AlgoliaOptions>();
options.ApiKey = algoliaOptions.ApiKey;
options.ApplicationId = algoliaOptions.ApplicationId;
options.SearchKey = algoliaOptions.SearchKey;
});
}
} |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Please forgive me, as I am primarily a php developer, getting familiar with Kentico 13 and .NET Core together.
I am attempting to get the Algolia integartion going, but am stuck on creating the custom class file referenced in the project. I created an included project inside of the Kentico Administation Project (CMSApp) called AlgoliaSearcg, with a class file (AlgoliaSearch.cs) containing the code extending the AlgoliaSearchModel class, however, I am still receiving the error: "Unable to resolve service for type 'Kentico.Xperience.AlgoliaSearch.Services.IAlgoliaIndexRegister' while attempting to activate 'Kentico.Xperience.AlgoliaSearch.Services.DefaultAlgoliaRegistrationService'."
Do you have a sample classfile or project to include in trhe Administration project that I can use to test with the Dancing Goat website?
Appreciate any help with this. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions