Need example on how to remove prefix from CustomerNumber, I got a hint that I should use ReadableCustomerIdService. But that only contains GetCustomerId
Litium version: 6.2.2-patch-1810041453
Need example on how to remove prefix from CustomerNumber, I got a hint that I should use ReadableCustomerIdService. But that only contains GetCustomerId
Litium version: 6.2.2-patch-1810041453
Implementing a custom decorator for the service with the service decorator pattern that can tweak and change what the service is returning. The _prefix
variable can be used to change the prefix to something else than the standard LSC
, in the below case we remove the prefix.
using System;
using Litium.Application.Customers;
using Litium.Common;
using Litium.Customers;
using Litium.Runtime.DependencyInjection;
namespace Litium.Accelerator.Mvc.App_Start
{
[ServiceDecorator(typeof(ReadableCustomerIdService))]
public class ReadableCustomerIdWithOwnPrefix : ReadableCustomerIdService
{
private readonly ReadableCustomerIdService _parent;
private readonly KeyLookupService _keyLookupService;
private const string _prefix = "";
public ReadableCustomerIdWithOwnPrefix(ReadableCustomerIdService parent, KeyLookupService keyLookupService)
{
_parent = parent;
_keyLookupService = keyLookupService;
}
public override string GetCustomerId()
{
var id = _prefix + _parent.GetCustomerId().Substring(3);
while (_keyLookupService.TryGetSystemId<Person>(id, out Guid systemId)
|| _keyLookupService.TryGetSystemId<Organization>(id, out systemId))
{
id = _prefix + _parent.GetCustomerId().Substring(3);
}
return id;
}
}
}
Remarks: The Litium.Application.Customers.ReadableCustomerIdService
service is an internal service and can be changed or removed without any notice.
Remarks 2: The ReadableCustomerIdService
can be decorated with multiple classes so it is not sure that the _parent.GetCustomerId()
-method will return a customer number that is starting with the LSC
and then the above .Substring(3)
to remove the prefix need to be changed to what it is returning.