【问题标题】:How to Implement MVP in Console Application?如何在控制台应用程序中实现 MVP?
【发布时间】:2009-09-18 14:59:07
【问题描述】:

我在控制台应用程序的 Program.cs 中有以下代码

class Program : IView
{
  private static ViewPresenter _presenter;

  static void Main(string[] args)
  {
      _presenter = new ViewPresenter(this);  
  }
}

但我不能将this 传递给演示者,因为主要方法是static。现在我该怎么做呢?

【问题讨论】:

    标签: c# design-patterns mvp console-application


    【解决方案1】:

    您必须创建Program 的实例。 Main 是一个静态方法。

    class Program : IView {
        private static ViewPresenter _presenter;
    
        static void Main(string[] args) {
            _presenter = new ViewPresenter(new Program());  
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 2015-09-03
      • 2018-06-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多