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

StackOverflow https://stackoverflow.com/questions/153222

  •  03-07-2019
  •  | 
  •  

Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top