使用 MVP - 如何正确使用事件进行测试
-
09-06-2019 - |
题
我刚刚开始在我正在构建(实际上是重新构建)的大型 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
或者应该在接口处定义一个事件?如果这是首选模式,如何添加要处理和使用的事件?
解决方案
我不知道是否有一个普遍喜欢的模式。我倾向于将事件添加到视图界面并让演示者响应视图。我在中描述了这种模式 更多详细信息请参见此处.
不隶属于 StackOverflow