我正在阅读Architecting Microsoft .Net Solutions for the Enterprise,并尝试弄清楚有关 Presenter 和服务层的一些事情。
首先,我的 Presenter 需要调用驻留在服务层中的方法,例如 initialize()、save() 等。但是我在哪里放置对服务层的引用?它应该在 Presenter 的类级别,还是应该在 Presenter 方法本身中定义一个新服务?
其次 - 这在书中也不是很清楚 - 这是从 Presenter 到服务层的处理方式吗?:
public void ProcessPrediction()
{
//Get the data from the View
string selectedForPolePosition = predictionPageView.DriverPolePosition;
string selectedForSecondPosition = predictionPageView.DriverSecondPosition;
string selectedForThirdPosition = predictionPageView.DriverThirdPosition;
string selectedForFourthPosition = predictionPageView.DriverFourthPosition;
string selectedForFifthPosition = predictionPageView.DriverFifthPosition;
string raceTitle = predictionPageView.RaceTitle;
//Prepare for sending to the Service Layer
PredictionDTO prediction = new PredictionDTO();
prediction.RaceTitle = raceTitle;
//More Filling of the DTO here....
//...
//...
IPredictionService predictionService = new PredictionService();
predictionService.ProcessPrediction(prediction);
}