I am developing a Web API as services layer for a ASP.NET web forms application.
There are two controllers ContractorController
(gives details about the contractor) and PaymentsController
(gives details about payments done to a contractor).
Now in our UI application we have this User-Control which will be used across many pages:
Is the responsibility of the UI to call the ContractorController
and PaymentsController
separately to get the required data? Or should I provide a Consolidated Method (may be on PaymentsController
) to give back all the required data, which seems to be going against RESTful approach or dealing with resources?
Thank you.
12
I would make it this way:
-
Encapsulate this UI piece into a component, that is responsible only for UI part of the job. Upon construction this component needs data about both contractor and payments to be provided to it (via constructor, some setter methods – whatever. Depends on your design)
-
Encapsulate database-related logic into two services (ContractorService and PaymentService). Those services can fetch data from database using conditions you provide and prepare it (convert types, fill related object instances, localize via calls to LocalizationService etc).
-
Now in any controller action (e.g. in any section /page of your website regardless of how controller is called) you first call respected services to fetch the data and then feed this data into your UI component.