You mean about service a remote facade (Web service) which will call application layer, because domain service is a different thing.
The remote facade layer (web service) if you are designing n-tier application to expose application services to other tiers will expose your business and commands by calling the application layer, the application layer as mentioned by David:
For Read Part, in your application layer you need to design a Query Service with methods like FindOrders(x, y, z)
, GetMostOrderedItems()
, ...
For the Write part, you can design the command service in one of many ways like:
- Service which takes DTOs and execute domain logic based on it [Least CQRS]:
public void ActivateOrder(int orderID)
{
var order = _orderRepository.FindOrder(orderID);
order.Activate();
}
public void UpdateClientAddress(ClientAddressDTO address)
{
var client = _clientRepository.FindClient(address.ClientID);
client.Address = // .. map ClientAddressDTO to Address
}
- Service which takes DTOs and convert it to a Command to be executed on domain model:
public void ActivateOrder(int orderID)
{
var orderActivationCommand = new OrderActivationCommand(orderID);
_commandExecuter.Execute(orderActivationCommand);
}
public void UpdateClientAddress(ClientAddressDTO address)
{
var clientMovingCommand = new clientMovingCommand(address.ClientID, address.PostalCode, ...);
_commandExecuter.Execute(clientMovingCommand);
}
- Generic Service which takes a Command object (instead of DTO) and execute it:
// ... in remote facade or client code ...
var orderActivationCommand = new OrderActivationCommand(orderID);
_commandService.ExecuteCommand(orderActivationCommand);
// ... in application layer (service) ...
public void ExecuteCommand(Command command)
{
_commandExeuter.Execute(command);
}