Definition managers

Version: 10.4

Definition managers are used to get, create, search, activate, and delete marketing activities.

Get definition manager in a Sitecore context

The following example demonstrates how to retrieve the IGoalDefinitionManager in a Sitecore context:

RequestResponse
using Sitecore.DependencyInjection;
using Sitecore.Marketing.Definitions;
using Sitecore.Marketing.Definitions.Goals;


namespace Documentation
{
    public class DefineAGoal
    {
        public void Example()
        {
            IDefinitionManager<IGoalDefinition> goalDefinitionManager = ServiceLocator.ServiceProvider.GetDefinitionManagerFactory().GetDefinitionManager<Sitecore.Marketing.Definitions.Goals.IGoalDefinition>();
        }
    }
}

Construct definition manager in a non-Sitecore context

The following example demonstrates how to construct the AutomationPlanDefinitionManager in a non-Sitecore context using the Reference Data Service as a repository.

Note

You must add a xdb.referencedata.client connection string to the application’s ConnectionStrings.config file that points to the Reference Data Service end point - for example, https://refdata/.

RequestResponse
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Sitecore.Marketing.Definitions;
using Sitecore.Marketing.Definitions.AutomationPlans;
using Sitecore.Marketing.Definitions.AutomationPlans.Model;
using Sitecore.Marketing.Definitions.Config;
using Sitecore.Marketing.ObservableFeed.Activation;
using Sitecore.Marketing.ObservableFeed.DeleteDefinition;
using Sitecore.Marketing.Operations.Xdb.ReferenceData.Model.Definitions.AutomationPlans;
using Sitecore.Marketing.Operations.Xdb.ReferenceData.Service.Definitions.AutomationPlans;
using Sitecore.Marketing.Search;
using Sitecore.Marketing.Taxonomy;
using Sitecore.Xdb.ReferenceData.Client;
using Sitecore.Xdb.ReferenceData.Core.Converter;
using Sitecore.Xdb.ReferenceData.Core.Results;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Sitecore.Marketing.Core.ObservableFeed;
using Sitecore.Xdb.Common.Web;

namespace Documentation
{
    public class DefinitionManagerExternal
    {
        public static AutomationPlanDefinitionManager CreatePlanDefinitionManager()
        {
            var loggerFactory = new LoggerFactory();

            // Replace value of FindValue= with certificate thumbprint for your reference data service
            CertificateWebRequestHandlerModifierOptions options =
            CertificateWebRequestHandlerModifierOptions.Parse("StoreName=My;StoreLocation=LocalMachine;FindType=FindByThumbprint;FindValue=15E6693B0AECB63DE57D991EC363CA462DC52432");

            // Optional timeout modifier
            IWebRequestHandlerModifier[] handlers = { new CertificateWebRequestHandlerModifier(options) };


            var refDataClient = new ReferenceDataHttpClient(
                new DefinitionEnvelopeJsonConverter(),
                handlers,
                new Logger<ReferenceDataHttpClient>(loggerFactory)
            );

            var repo = new PlanDefinitionReferenceDataRepository(
                refDataClient,
                new PlanDataConverter(),
                new GuidMonikerConverter(),
                new DefinitionOperationResultDiagnostics()
            );

            var services = new ServiceCollection();

            services.AddSingleton<ITaxonomyManagerProvider, TaxonomyManagerProvider>();
            services.AddSingleton<ITaxonomyClassificationResolver<IAutomationPlanDefinition>, DefaultClassificationResolver<IAutomationPlanDefinition>>();
            services.AddSingleton<FieldTaxonomyMap<IAutomationPlanDefinition>>();

            IServiceProvider serviceProvider = services.BuildServiceProvider();

            var classificationResolver = serviceProvider.GetRequiredService<ITaxonomyClassificationResolver<IAutomationPlanDefinition>>();

            return new AutomationPlanDefinitionManager(
                repo,
                classificationResolver,
                new NotSupportedSearchProvider<IAutomationPlanDefinition>(),
                new ActivationRetryingObservableFeed<IAutomationPlanDefinition>(new Logger<ActivationRetryingObservableFeed<IAutomationPlanDefinition>>(loggerFactory)),
                new DummyDeleteDefinitionObservableFeed(),
                new DefaultDefinitionManagerSettings()
            );
        }

        class DummyDeleteDefinitionObservableFeed : IDeleteDefinitionObservableFeed<IAutomationPlanDefinition>
        {
            public void NotifyObservers(DeleteDefinitionArgs<IAutomationPlanDefinition> value)
            {
            }

            IList<Sitecore.Marketing.Core.ObservableFeed.IObserver<DeleteDefinitionArgs<IAutomationPlanDefinition>>> IObservableFeed<DeleteDefinitionArgs<IAutomationPlanDefinition>>.Observers
            {
                get;
            }
        }

    }
}

Do you have some feedback for us?

If you have suggestions for improving this article,