This is a loaded question but I'll try to answer it to some extend.
I highly recommend looking at the github sample from Vaughn Vernon. He is the author of Implementing Domain Driven Design.
The definition of services is laid out very nicely in the SO link you provided. So I'm going to just give you sample codes to digest with that description.
Take the example of provisioning a tenant in an identity access domain.
Here are a few pretty clear examples from Vaughn's github:
Here is the tenant domain object:
package com.saasovation.identityaccess.domain.model.identity;
public class Tenant extends extends ConcurrencySafeEntit {
public Tenant(TenantId aTenantId, String aName, String aDescription, boolean anActive) {
...
}
public Role provisionRole(String aName, String aDescription) {
...
}
public void activate(){}
public void deactivate(){}
....
}
The tenant Repository:
package com.saasovation.identityaccess.domain.model.identity;
public interface TenantRepository {
public void add(Tenant aTenant);
}
Tenant domain service:
package com.saasovation.identityaccess.domain.model.identity;
public class TenantProvisioningService {
private TenantRepository tenantRepository;
public Tenant provisionTenant(
String aTenantName,
String aTenantDescription,
FullName anAdministorName,
EmailAddress anEmailAddress,
PostalAddress aPostalAddress,
Telephone aPrimaryTelephone,
Telephone aSecondaryTelephone) {
Tenant tenant = new Tenant(
this.tenantRepository().nextIdentity(),
aTenantName,
aTenantDescription,
true); // must be active to register admin
this.tenantRepository().add(tenant);
}
}
This is an application service:
package com.saasovation.identityaccess.application;
@Transactional
public class IdentityApplicationService {
@Autowired
private TenantProvisioningService tenantProvisioningService;
@Transactional
public Tenant provisionTenant(ProvisionTenantCommand aCommand) {
return
this.tenantProvisioningService().provisionTenant(
aCommand.getTenantName(),
aCommand.getTenantDescription(),
new FullName(
aCommand.getAdministorFirstName(),
aCommand.getAdministorLastName()),
new EmailAddress(aCommand.getEmailAddress()),
new PostalAddress(
aCommand.getAddressStateProvince(),
aCommand.getAddressCity(),
aCommand.getAddressStateProvince(),
aCommand.getAddressPostalCode(),
aCommand.getAddressCountryCode()),
new Telephone(aCommand.getPrimaryTelephone()),
new Telephone(aCommand.getSecondaryTelephone()));
}
}