forked from nemanjarogic/DesignPatternsLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOrderManager.cs
38 lines (30 loc) · 1.03 KB
/
OrderManager.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
namespace OrderProcessing;
public class OrderManager
{
private readonly IServiceLocator _serviceLocator;
private readonly Logger _logger;
public OrderManager(IServiceLocator serviceLocator)
{
_serviceLocator = serviceLocator;
_logger = _serviceLocator.GetService<Logger>();
}
public void ProcessOrder(Order order)
{
_logger.Log("Processing new order...");
var totalPrice = order.UnitPrice * order.Quantity;
var paymentProcessor = _serviceLocator.GetService<PaymentProcessor>();
var isPaymentSuccessful = paymentProcessor.ProcessPayment(totalPrice);
NotifyCustomer(isPaymentSuccessful);
}
private void NotifyCustomer(bool isPaymentSuccessful)
{
var notifier = _serviceLocator.GetService<NotificationManager>();
if (isPaymentSuccessful)
{
notifier.NotifyCustomer("Payment succeeded");
return;
}
notifier.NotifyCustomer("Payment failed");
_logger.Log("Payment failed");
}
}