November Happy Hour will be moved to Thursday December 5th.

Hide Episerver Visitor Group Criteria

Vote:
 

Hi,
I am currently on Episerver 11.6 and am looking to start using the personalization in Episerver.

Creating custom Criteria classes is very simple. I've created several of my own, but would like to hide some of the built in ones. Is it possible to hide specific built in personalization criterias?

-Paul

#204548
Jun 05, 2019 21:29
Vote:
 

Hi Paul,

These are just resolved through dependency injection, in fact, if you look at the VisitorGroupCriterionAttribute you can see it implements the ServicePlugInAttributeBase.

That means that ejecting the registered instances should make them unavailable. It's not that obvious how to do this via StructureMap, but I quickly tested the following and it seems to work (no guarantees!):

[InitializableModule]
[ModuleDependency(typeof(DependencyResolverInitialization))]
public class RemoveVisitorGroupCriteriaInitialization : IConfigurableModule
{
    public void Initialize(InitializationEngine context) { }
    public void Uninitialize(InitializationEngine context) { }
    public void ConfigureContainer(ServiceConfigurationContext context)
    {
        // If you wanted to remove all criteria
        //context.Services.RemoveAll<ICriterion>();

        // Remove selected criteria
        var criteriaTypes = new List<Type>
        {
            // Site Criteria
            typeof(NumberOfVisitsCriterion),
            typeof(SelectedLanguageCriterion),
            typeof(UserProfileCriterion),
            typeof(ViewedCategoriesCriterion),
            typeof(ViewedPagesCriterion),
            // Time and Place Criteria
            typeof(TimeOfDayCriterion)
        };

        var criterionPluginConfig = context.StructureMap().Model.PluginTypes
            .SingleOrDefault(x => x.PluginType == typeof(ICriterion));

        if (criterionPluginConfig == null)
        {
            return;
        }

         var instances = criterionPluginConfig.Instances.Where(x => criteriaTypes.Contains(x.ReturnedType));

        foreach (var instance in instances)
        {
            criterionPluginConfig.EjectAndRemove(instance);
        }
    }
}

/Jake

#204554
Edited, Jun 06, 2019 22:40
Vote:
 

This is extremly helpful and is exactly what I wanted. Thank you!

#204562
Jun 07, 2019 13:28
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.