我有兩個聚合,廣告商和付款。在應用服務中注入底層接口
我使用的是Paypal和Authorize.net支付網關。所以我在底層創建了接口。
interface IPaymentMethod
{
void ProcessPayment(PaymentInfo paymentInfo);
}
並在底層再次實現它。
Public class PaypalPaymentGateway : IPaymentMethod
{
public void ProcessPayment(PaymentInfo paymentInfo)
{
// call Paypal api and pass paymentinfo
}
}
//同爲authorize.net支付網關 下面是我的應用程序服務類
public class PaymentGatewayService : IPaymentGatewayService
{
IPaypalMethod paypalMethod;
public PaymentGatewayService(IPaypalMethod paypalMethod)
{
this.paypalMethod = paypalMethod;
if (paypalMethod == null)
throw new Exception("PaypalMethod not initialized");
}
public void DepositFundInAdvertiser
(PaymentInfo paymentInfo, RegistrationID advertiserRegistrationID)
{
if (paymentMethod != null)
throw new Exception("PaymentMethod empty.");
PaymentResult paymentResult=
paymentMethod.ProcessPayment(paymentInfo);
Advertiser advertiser = advertiserRepository
.Find(advertiserRegistrationID);
advertiser.AddAdvertiserFund(paymentInfo.PaymentTotal);
advertiserRepository.Save(advertiser);
}
}
在應用層 - 我可以在注入層應用程序構造PaypalMethod接口和做DepositFundInAdvertiser方法如下?
記住IPaypalMethod是在底層創建和實現的。
「只有我會定義域層,而不是基礎設施層內IPayer抽象。」你的方法,是我以前做過,但我的同事告訴我,像IPaymentRepository我們因此未在我們的領域注入,但使用應用程序服務來處理所有,同樣在這裏,他也反對在域模型中注入IPayer。他告訴我,它緊密耦合或域名,他也給我的網址,它被阻止在域模型中注入IPaymentRepository。請建議我有效的點數,以便我可以將它們提供給我的同事。 – kamal 2011-05-09 10:05:26
模型應該是持久的無知。因此 - 它應該對存儲庫一無所知。但支付能力是一個領域問題,因此 - 它應該生活在領域。至少我是這麼看的。 – 2011-05-09 10:59:50
我同意你的同事。在應用服務層中注入IPaymentRepository。但阿爾尼斯有一點。領域層應該模擬現實,並且這是在付款成功或不成功時採取的行動。通知付款人/用戶,打印筆記等。看到我的回答如下... – 2011-05-09 11:16:15