MVP pattern - Passive View and exposing complex types through IView (Asp.Net, Web Forms)

寵の児 提交于 2020-01-01 14:25:15

问题


I've recently switch to MVP pattern with a Passive View approach. I feel it very comfortable to work with when the view interface exposes only basic clr types, such as string mapped to TextBoxes, IDictionary mapped to DropDownLists, IEnumerable mapped to some grids, repeaters.

However, this last approach works only when from those grid I care only about one collumn. How can I map grid's multirow content inside IView ? For now, two solutions comes to my mind, both not brilliant:

  1. Create a DTO for the grid's content and expose the IEnumerable in IView, or
  2. Expose the IEnumerable or just the "grid" as is in IView.

First solution seems to break the Passive View rules while going closer to Supervising Controller pattern and second breaks the whole MVP pattern at all. How would do you handle this?

thanks, Łukasz


回答1:


MVP makes webforms development much easier, except in cases like this. However, if you used TDD to verify that your IView really needs that grid of data, then I don't really see what the problem is.

I assume you're trying to do something like this:

public interface IView
{
 DataTable DataSource {get; set;}
}

public class View : IView {

private GridView _datasource;
public DataSource 
{
  get { return _datasource; }
  set 
  { 
    _datasource = value; 
    _datasource.DataBind(); 
  }
}

When used with the MVP pattern, I find this little pattern to be quite helpful.



来源:https://stackoverflow.com/questions/153222/mvp-pattern-passive-view-and-exposing-complex-types-through-iview-asp-net-we

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