我正在阅读架构企业的Microsoft .NET解决方案,我试图弄清楚有关演示者和服务层的几件事。

首先关闭,我的演示者需要调用驻留在服务层中的方法,如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);
    }
.

有帮助吗?

解决方案

 IPredictionService predictionService = new PredictionService();
.

这将真的取决于大量因素:

  • 终身服务器的服务和寿命
  • 如果您使用的是任何di工具
  • 如果需要处理服务
  • 如果服务具有任何空闲超时(例如,如果它是 WCF Proxy

    本质上,它不一定是建筑设计 - 它更像是设计决策。

    如果使用di工具,您可以:

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

    甚至更好,均不是,只需将其声明为属性和di工具可以在创建演示者时填充它。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top