Avoiding the IClientApiService

So, I’ve blogged previously about my problems with the IClientApiService on a Content Management (CM) server. See https://andrewwburns.com/2018/08/15/unable-to-resolve-service-for-type-sitecore-emailcampaign-cd-services-iclientapiservice-while-attempting-to-activate/

Well, I asked Sitecore support about it, and they gave a really helpful response:

// This should be injected rather than calling the ServiceLocator
IMessageBus automatedMessageBus = ServiceLocator.ServiceProvider.GetService<IMessageBus>()
AutomatedMessage automatedMessage = new AutomatedMessage()
{
ContactIdentifier = contactIdentifier,
MessageId = emailCampaignId
};
automatedMessageBus.Send(automatedMessage);

Their reasoning for this was:

It is not recommended to add the configuration on CM since:
1) It is not enough to add only the <configurator> section, since it has dependencies on other configuration sections.
2) The CustomServiceConfigurator may change in the next release and the functionality will stop working.

Fair enough, seems sensible, though I’m now slightly at a loss for what the IClientApiService is actually for. I’ve tried the code they’ve send across, and it sends email correctly (and yes, I used DI, rather than a ServiceLocator).

I’ve tested this code locally, and it works nicely; I haven’t yet had a chance to try it on a scaled environment. I also decompiled the relevant assemblies, and yes, behind the IClientApiService implementations it seems to use a MessageBus<AutomatedMessage> object, so this should be equivalent.

Advertisement
Avoiding the IClientApiService

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.