【问题标题】:Using MVP - How to use Events Properly for Testing使用 MVP - 如何正确使用事件进行测试
【发布时间】:2010-09-07 00:42:47
【问题描述】:

我刚刚开始在我正在构建(实际上是重新构建)的大型 ASP.NET 应用程序中使用 MVP 模式,我很难弄清楚我应该如何使用应用于视图的事件。

假设我在用户控件中有 2 个下拉列表,其中一个取决于另一个的值:

<%@ Control Language="vb" AutoEventWireup="false" CodeBehind="ucTestMVP.ascx.vb" Inherits=".ucTestMVP" %>    
<asp:DropDownList ID="ddlCountry" runat="server" AutoPostBack="True" />
<asp:DropDownList ID="ddlCity" runat="server" />

AutoPostBack 事件应该如何在接口中定义?它是否应该是由用户控件处理的事件,如下所示:

Public Partial Class ucTestMVP
  Inherits System.Web.UI.UserControl
  Implements ITestMVPView

  Protected Sub PageLoad(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not Page.IsPostBack Then
      Dim presenter As New TestMVPPresenter(Me)
      presenter.InitView()
    End If
  End Sub

  Private Sub ddlCountrySelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlCountry.SelectedIndexChanged
    Dim presenter as New TestMVPPresenter(Me)
    presenter.CountryDDLIndexChanged()
  End Sub

End Class

或者应该在接口上定义一个事件?如果这是首选模式,我该如何添加要处理和使用的事件?

【问题讨论】:

    标签: asp.net design-patterns mvp


    【解决方案1】:

    我不知道是否存在普遍首选的模式。我倾向于将事件添加到视图界面并让演示者响应视图。我在more detail here 中描述了这种模式。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-05-14
      • 2013-06-26
      • 2017-10-28
      • 1970-01-01
      • 1970-01-01
      • 2018-07-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多