I want to use design pattern to solve the problem I have at hand. I have 3 set of business rules and depending on each business rules, I determine the payment gateway to call.
- If amount is 0 to 1000 use xx gateway.
- If amount is 1100 to 2000 use xxx gateway.
I have created my set of different business rules like this:
public interface IRules
{
void Validate(decimal amount);
}
Implementations:
public class CheapRule : IRules
{
public void Validate(decimal amount)
{
if (amount <= 20)
{
//use cheap Gateway
}
}
}
I define a single interface called IPaymentGateway
with two concrete implementations CheapPaymentGateway
and ExpensivePaymentGateway
.
public interface IPaymentGateway
{
void MakePayment(PaymentModel model);
}
Implementations:
public class CheapPaymentGateway : IPaymentGateway
{
public void MakePayment(PaymentModel model)
{
//Use CheapPaymentGateway
}
}
Depending on the amount entered by the user from client code, at runtime I want one of one of the gateway to be used based on the defined business rules. Please how do i achieve this using .net core. Also how do i inject the dependencies at startup since one interface uses multiple implementations. any guidelines will be much appreciated.