3

私はエンタープライズ向けのMicrosoft.Netソリューションの設計を読んでおり、プレゼンターとサービスレイヤーに関していくつかのことを理解しようとしています。

まず、Presenterは、initialize()、save()など、サービスレイヤーに存在するメソッドを呼び出す必要があります。しかし、サービスレイヤーへの参照はどこに配置しますか?プレゼンターでクラスレベルにする必要がありますか、それともプレゼンターメソッド自体で新しいサービスを定義する必要がありますか?

第二に、これは本でもあまり明確ではありませんが、これはプレゼンターからサービスレイヤーへの処理がどのように機能するのですか?:

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);
    }
4

1 に答える 1

2
 IPredictionService predictionService = new PredictionService();

これは、実際には多くの要因に依存します。

  • サービスの存続期間とプレゼンターの存続期間
  • DI ツールを使用している場合
  • サービスの廃棄が必要な場合
  • サービスにアイドル タイムアウトがある場合 (たとえば、サービスがWCF プロキシの場合)

つまり、本質的には、必ずしもアーキテクチャの設計ではなく、むしろ設計上の決定です。

DI ツールを使用する場合は、次のいずれかを行います。

 IPredictionService predictionService = diContainer.Resolve<IPredictionService>();

または、さらに良いことに、上記のどれも使用せず、プロパティとして宣言するだけで、プレゼンターを作成するときに DI ツールで入力できます。

于 2011-03-27T19:18:58.473 に答える