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.

Advertisements
Avoiding the IClientApiService

Unable to resolve service for type ‘Sitecore.EmailCampaign.Cd.Services.IClientApiService’ while attempting to activate…

A colleague had this error occur while setting up a production system. Everything had been fine in development, but Dependency Injection seemed to be throwing a wobbly when it tried to load the service we’d written for adding/removing contacts from a subscription list.

Edit: I raised this problem with Sitecore and got a helpful response: https://andrewwburns.com/2018/08/17/avoiding-the-iclientapiservice/

Continue reading “Unable to resolve service for type ‘Sitecore.EmailCampaign.Cd.Services.IClientApiService’ while attempting to activate…”

Unable to resolve service for type ‘Sitecore.EmailCampaign.Cd.Services.IClientApiService’ while attempting to activate…