3
我正在閱讀構建Microsoft .Net解決方案的企業,我嘗試瞭解關於演示者和服務層的一些事情。MVP - 演示者和服務層 - 在哪裏聲明服務層
首先,我的演示需要調用駐留在服務層的方法,如初始化(),保存()等,但我在哪裏放置到服務層中的參考?它應該是在演示一流水平,或者我應該定義演示方法本身就是一個新的服務?
二 - 這是不是在這本書真正明確要麼 - 這是從主持人到服務層的處理是如何工作的?:
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);
}
_LifeTime - 直至現在只是被用來通過主持人的一個方法一次。 _如果您使用任何DI工具_ - 不,我沒有使用任何工具。 _如果服務需要處理_ - 就像在使用?不,不是必需的。 _如果服務有任何空閒超時_ - 否,它沒有。 最後一個選項聽起來不錯。但這意味着在視圖中使用DI工具來實例化演示者和服務,對吧? – 2011-03-27 19:30:13
如果不需要部署和無空閒超時,我要再次聲明它爲成員,並在構造函數初始化它。或者只是使用像溫莎城堡或Unity這樣的東西來照顧對象創作。無論如何,將它作爲成員變量更有意義 – Aliostad 2011-03-27 19:40:16