In the following example, the AccountService and ProductService are in an ASP.NET MVC app. The AccountWebAPI and ProductWebAPI are externally hosted API micro services.
1) Can I eliminate the ProductService and orchestrate the retrieving of the orders in the CustomerAccountController itself? This is because I consider the Controller as the Application layer/service which is mentioned in the DDD (Domain Driven Design).
2) Am I violating the n-layer architecture because the ProductService calls the AccountService which is the same layer?
3) Since AccountWebAPI and ProductWebAPI are micro services, do they have to be separated as AccountService and ProductService in the client application (MVC App) also to keep the Separation Of Responsibility? So the ProductService needs to be renamed as ProductAppService and ProductService should interact with ProductWebAPI only like AccountService talks to AccountWebAPI.
public class CustomerAccountController : Controller
{
IProductService _productService;
public CustomerAccountController(IProductService productService)
{
_productService = productService;
}
public IActionResult Index()
{
return View();
}
public IActionResult Account(int customerId)
{
var orders = _productService.GetOrders(customerId);
return View(orders);
}
}
public class ProductService
{
IAccountService _accountService;
IProductWebAPI _productWebAPI;
ProductService(IAccountService accountService, IProductWebAPI productWebAPI)
{
_accountService = accountService;
_productWebAPI = productWebAPI;
}
IList<Order> GetOrders(int customerId)
{
// Find the International Customer Number for CustomerId
object customer = _accountService.GetInternationCustomerInfo(customerId);
// Convert the string type to int
var modifiedCustomerNumber = Convert.ToInt32(customer.Id);
// Get the orders
return _productWebAPI.GetOrders(modifiedCustomerNumber);
}
}
public class AccountService
{
IAccountWebService _accountWebAPI;
CustomerService(IAccountWebService accountWebAPI)
{
_accountWebAPI = accountWebAPI;
}
object GetInternationCustomerInfo(int customerId)
{
return accountWebAPI.GetCustomer(customerId)
}
}
UPDATE: I realized that OrderService would be the appropriate service name for orders and not ProductService.
The LAYERS:
VIEW -- CONTROLLER -- SERVICE -- WebAPIs -- DOMAIN -- REPOSITORY
OrderView -- CustomerAccountController -- ProductService (calls AccountService in the same layer) -- ProductWebAPI -- ProductDomain -- ProductRepository