新しいビジネス ルールを簡単に追加できるスケーラブルな販売注文プロジェクトを作成する方法を探しています。
public class OrderLine
{
public int OrderId { get; set; }
public int Line { get; set; }
public string Product { get; set; }
public string Description { get; set; }
public decimal Quantity { get; set; }
public int LeadTimeDays { get; set; }
public DateTime ShipDate { get; set; }
}
注文明細行が有効であることを確認するためのビジネス ルールを作成するためのベスト プラクティスは何ですか? そして、それぞれにチェックメソッドを追加せずに複数のルールを適用する簡単な方法はありますか?
public static class OrderLineChecks
{
public static void CheckLeadTime(this OrderLine orderLine)
{
if( (orderLine.ShipDate - DateTime.Today).TotalDays < orderLine.LeadTimeDays )
throw new Exception("Order is within lead time.");
}
public static void CheckShipDateError(this OrderLine orderLine)
{
if(orderLine.ShipDate < DateTime.Today)
throw new Exception("Ship date cannot be before today.");
}
public static void ShouldBeOrderedInPairs(this OrderLine orderLine)
{
if(orderLine.Description.Contains("pair") && (orderLine.Quantity % 2 !=0))
throw new Exception("Quantities must be even numbers.");
}
public static NextFutureRuleHere(...)
{
}
}
アドバイスありがとうございます。