How to: Use a Module Controller from a Presenter
This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies.
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.
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.
The following procedure describes how to reference the module controller in your presenter classes.
To reference the module controller in your presenter class
- In your presenter class, add a private field for the controller. The following code shows a private field for a controller of type ICustomersController.
- Create a constructor that receives a controller instance as a parameter and stores it in the private field, as shown in the following code.
- 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.
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.
You will have a presenter class that consumes the module controller to handle user events.
The next step is to implement navigation logic. Typically, navigation logic is implemented in the module controller.