Export (0) Print
Expand All

How to: Use a Module Controller from a Presenter

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies.
This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

When you create a business module with the Add Business Module template, the template creates a controller class for the module. You can use this class to implement business and navigation logic consumed by the presenters in the module.

This topic describes how to access and use a module controller from a presenter.

Prerequisites

This topic assumes that you have an existing Web client solution with a business module. For information about how to create a Web client solution, see How to: Create a Web Client Solution. For information about how to create a business module, see How to: Create a Business Module.

Steps

The following procedure describes how to reference the module controller in your presenter classes.

To reference the module controller in your presenter class

  1. In your presenter class, add a private field for the controller. The following code shows a private field for a controller of type ICustomersController.
    private ICustomersController _controller;
    
  2. Create a constructor that receives a controller instance as a parameter and stores it in the private field, as shown in the following code.
    public ApproveCustomerViewPresenter(ICustomersController controller)
    {
        _controller = controller;
    }
    
  3. Add the CreateNew attribute to the constructor parameter. When you do this, ObjectBuilder injects a new instance of the application controller when it constructs the presenter.
    public ApproveCustomerViewPresenter([CreateNew] ICustomersController controller)
    {
        _controller = controller;
    }
    

The following procedure describes how to handle user events in your presenter classes.

To handle user events in your presenter classes

  • Add code to the presenter methods that the view calls in response to user interaction. These methods call the controller and update the state of the view. For example, the following code shows a method named OnApproveCustomer which is called by the view when the user wants to approve a customer. The OnApproveCustomer method forwards the request to the application controller which executes the business and navigation logic required to approve a customer.
    public void OnApproveCustomer()
    {
        _controller.ApproveCurrentCustomer();
    }
    

Outcome

You will have a presenter class that consumes the module controller to handle user events.

Next Steps

The next step is to implement navigation logic. Typically, navigation logic is implemented in the module controller.

Show:
© 2014 Microsoft