MVP Template - Design Question

We are trying to use the MVP pattern in our current project (asp.net application) and have encountered some problems. The page has several sections, and we use custom controls for these independent sections. Now each user control has its own view and presenter, and the page acts as the base view. Now the question is how to transfer the data necessary for user control?

In accordance with the current design, the page host will receive the necessary data for the entire page. How can this data be transferred to a user management presentation?

Another approach that we are thinking of is to instead create only views for user controls and use page presentations to handle all events. In this case, we will use several presentation interfaces that will be implemented using each user control type. But how would the lead page interact with all the different views?

Thanks, JBN

+3
source share
3 answers

Why do user controls have their own representations and presenters?

. , , . .

:

IFooPageView
{
  string SomeData {get; set;}
  event EventHandler SomeEvent;
}

public class FooPageView : IFooPageView
{
   public event EventHandler SomeEvent;
   public SomeData 
   {
         get { return myUserControl.SomeData;}
         set { myUserControl.SomeData = value;}
   }   

   protected override void OnInitComplete(EventArgs e)
   {
     //handle the user control event
     this.myUserControl.SomeEvent += SomeEvent_EventHandler;
   }

   private void SomeEvent_EventHandler(object sender, EventArgs e)
    {            
        //Raise the user control event to the presenter
        if (SomeEvent!= null)
            SomeEvent(this, EventArgs.Empty);
    }
}

Phil Haack ASP.NET( )

MVP -.

+1

,

1. , , , .

0

Not sure if it exactly matches the MVP, but you can open the (View) property from your UC and update it using the data on your page.

0
source

Source: https://habr.com/ru/post/1782473/


All Articles