Last active
May 18, 2019 15:00
-
-
Save mattbrailsford/dbd5dac4eb76d387ea81771b71b4213a to your computer and use it in GitHub Desktop.
Possible API Gateway Implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IOrderService { | |
IEnumerable<IOrder> GetOrders(Guid storeId); | |
IOrder GetOrder(Guid storeId, Guid id); | |
IOrder CreateOrder(Guid storeId); | |
void SaveOrder(IOrder order); | |
void DeleteOrder(IOrder order); | |
} | |
public interface ICurrencyService { | |
IEnumerable<ICurrency> GetCurrencies(Guid storeId); | |
ICurrency GetCurrency(Guid storeId, Guid id); | |
ICurrency CreateCurrency(Guid storeId); | |
void SaveCurrency(ICurrency currency); | |
void DeleteCurrency(ICurrency currency); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class OrderService : IOrderService | |
{ | |
public IEnumerable<IOrder> GetOrders(Guid storeId) { ... } | |
public IOrder GetOrder(Guid storeId, Guid id) { ... } | |
public IOrder CreateOrder(Guid storeId) { ... } | |
public void SaveOrder(IOrder order) { ... } | |
public void DeleteOrder(IOrder order) { ... } | |
} | |
public class CurrencyService : ICurrencyService | |
{ | |
public IEnumerable<ICurrency> GetCurrencies(Guid storeId) { ... } | |
public ICurrency GetCurrency(Guid storeId, Guid id) { ... } | |
public ICurrency CreateCurrency(Guid storeId) { ... } | |
public void SaveCurrency(ICurrency currency) { ... } | |
public void DeleteCurrency(ICurrency currency) { ... } | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface IMyApi : IOrderService, ICurrencyService | |
{ } | |
public class MyApi : IMyApi | |
{ | |
private readonly Lazy<IOrderService> _orderService; | |
private readonly Lazy<ICurrencyService> _currencyService; | |
public MyApi(Lazy<IOrderService> orderService, | |
Lazy<ICurrencyService> currencyService) | |
{ | |
_orderService = orderService; | |
_currencyService = currencyService; | |
} | |
#region IOrderService | |
public IEnumerable<IOrder> GetOrders(Guid storeId) | |
=> _orderService.Value.GetOrders(storeId); | |
public IOrder GetOrder(Guid storeId, Guid id) | |
=> _orderService.Value.GetOrder(storeId, id); | |
public IOrder CreateOrder(Guid storeId) | |
=> _orderService.Value.CreateOrder(storeId); | |
public void SaveOrder(IOrder order) | |
=> _orderService.Value.SaveOrder(order); | |
public void DeleteOrder(IOrder order) | |
=> _orderService.Value.DeleteOrder(order); | |
#endregion | |
#region ICurrencyService | |
public IEnumerable<ICurrency> GetCurrencies(Guid storeId) | |
=> _currencyService.Value.GetCurrencies(storeId); | |
public ICurrency GetCurrency(Guid storeId, Guid id) | |
=> _currencyService.Value.GetCurrency(storeId, id); | |
public IOrder CreateCurrency(Guid storeId) | |
=> _orderService.Value.CreateCurrency(storeId); | |
public void SaveCurrency(ICurrency currency) | |
=> _currencyService.Value.SaveCurrency(currency); | |
public void DeleteCurrency(ICurrency currency) | |
=> _currencyService.Value.DeleteCurrency(currency); | |
#endregion | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MyClass { | |
private readonly IMyApi Api { get; }; | |
public MyClass(IMyApi myApi) | |
{ | |
Api = myApi; | |
} | |
public void DoSomething() { | |
var storeId = Guid.Parse("bf1b4497-db74-45df-b226-53718349c988"); | |
var orderId = Guid.Parse("6549499a-b49c-4163-ab22-cf9d3514a28b"); | |
var currency = Api.CreateCurrency(storeId); | |
currency.name = "Great British Pounds"; | |
currency.code = "GBP"; | |
Api.SaveCurrency(currency); | |
var order = Api.GetOrder(storeId, orderId); | |
order.CurrencyId = currency.Id; | |
Api.SaveOrder(order); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment