BLL と DAL の関係について少し混乱しています。BLL は依存性注入を介して DAL をカプセル化する必要がありますか? それとも、BLL はドメイン オブジェクトに対してのみ動作し、DAL は個別に保存/更新する必要がありますか?
たとえば、(典型的な MVC アプリで) 注文を更新して在庫を更新する必要がある Cancel Order 関数を想像してみてください。私の行動は次のようになりますか?
public ActionResult CancelOrder (Guid orderId) {
Order order = orderRepository.Get(orderId);
StockItem stockItem = stockRepository.Get(order.StockItemId);
_orderService.CancelOrder(order, stockItem);
orderRepository.Update(order);
orderRepository.Update(stock);
Return View();
}
または、次のようにする必要がありますか?
public ActionResult CancelOrder (Guid orderId) {
_orderService.CancelOrder(orderId);
Return View();
}
(within OrderService)
public void CancelOrder(Guid orderId) {
Order order = orderRepository.Get(orderId);
StockItem stockItem = stockRepository.Get(order.StockItemId);
order.Cancelled = true;
stockItem.AmountInStock = stockItem.AmountInStock + order.Amount;
orderRepository.Update(order);
orderRepository.Update(stock);
}
このオプションを使用すると、データ アクセスを含むすべてが BLL によって処理されます。リポジトリは密結合を避けるために注入されます。エンティティの取得は_orderService.GetOrder(orderId);
、リポジトリに直接行くのと同じように行われます。
時間があまりないので、例が粗雑ですみません。私が書いたことのどれかが少しでも理にかなっていますか、それとも私は荒野にいますか?