-
Notifications
You must be signed in to change notification settings - Fork 2
How to create View and Presenter
marektihkan edited this page Sep 13, 2010
·
1 revision
- Create Presenter interface to
Presentation.Presenters.(BoundedContext)
namespace - Create Presenter implementation to
Presentation.Presenters.(BoundedContext).Impl
namespace and inherit from its interface - Create View interface to
Presentation.Views.(BoundedContext)
- Create Page/UserControl to
Web.(BoundedContext)
namespace and inherit from its interface andArc.Infrastructure.Presentation.Mvp.Page/UserControl<TPresenterInterface>
- Add presentation logic to Presenter
- Override
HookUpEvents
on Page/UserControl - Register events to presenter using Presenter property and
Arc.Domain.Dsl
if needed - Register Presenter to Service Locator if needed (use conventions for less configuration)
- Presenter’s constructor should have parameter named “view” with type of View’s intetrface
namespace ExampleSolution.Presentation.Presenters.Examples
{
public interface IExamplePresenter
{
void Initialize();
void ChangeGreeting();
}
}
namespace ExampleSolution.Presentation.Presenters.Examples.Impl
{
public class ExamplePresenter : IExamplePresenter
{
private readonly IExampleView _view;
public ExamplePresenter(IExampleView view)
{
_view = view;
}
public void Initialize()
{
_view.Greeting = "Goodbye, World";
}
public void ChangeGreeting()
{
var greeting = _view.NewGreeting;
if (!string.IsNullOrEmpty(greeting))
{
_view.Greeting = greeting;
_view.NewGreeting = string.Empty;
}
}
}
}
namespace ExampleSolution.Presentation.Views.Examples
{
public interface IExampleView
{
string Greeting { get; set; }
string NewGreeting { get; set; }
}
}
Default.aspx
<h1><asp:Label ID="greetingLabel" runat="server" /></h1>
<p>
<asp:TextBox ID="newGreetingTextBox" runat="server" /> <asp:Button ID="submitButton" runat="server" Text="Tervita" />
</p>
Default.aspx.cs
namespace ExampleSolution.Web.Examples
{
public partial class Default : Page<IExamplePresenter>, IExampleView
{
protected override void HookupEventHandlers()
{
Load += (x, y) => Presenter.Initialize();
submitButton.Click += (x, y) => Presenter.ChangeGreeting();
}
public string Greeting
{
get { return greetingLabel.Text; }
set { greetingLabel.Text = value; }
}
public string NewGreeting
{
get { return newGreetingTextBox.Text; }
set { newGreetingTextBox.Text = value; }
}
}
}