MVP - Presenter and the Service Layer - Where to declare Service Layer

亡梦爱人 提交于 2019-12-05 23:18:44
 IPredictionService predictionService = new PredictionService();

This will really depend on a lot of factors:

  • Lifetime of the service and lifetime of the presenter
  • If you are using any DI tool
  • If the service needs to be disposed
  • If service has any idle timeout (for example if it is a WCF proxy)

So in essence, it is not necessarily an architectural design - it is more of design decision.

If you use a DI tool, you would either:

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

Or even better, none of above and just declare it as property and DI tool can populate it when it creates the presenter.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!