Reputation: 6878
I am trying to model the equivalent of a bounded context as outlined by Fowler here, using WebAPI endpoint(s).
Basically, I have a "Contact" DTO which is representative of a CRM centric view of a customer. A sales or a billing centric view of a "Contact" might be different, involving querying attributes from multiple tables to construct their view of "Contact".
In WebAPI, typically there would be a "Contacts" controller that would return a collection of "ContactDTOs".
What is the best way to support the above scenario in a clean, RESTful way using WebAPI?
Some thoughts below:
a. Create a separate action for each use case, and return a different DTO such as "SalesContactDTO", "BillingContactDTO" in the ContactsController
http://hostname/api/SalesContacts http://hostname/api/BillingContacts http://hostname/api/CRMContacts
b. Create separate controllers in which the Get() return the appropriate DTO.
"SalesContactsController" "BillingContactsConroller"
c. Create a single "ContactsController", set a "request header" that indicates which Contact "view" to return:
public ContactDTOBase[] Get()
{
//read request header
var contactType = Request.GetHeaders("whatever");
switch(contactType)
{
case "Billing":{ return new SalesContactDTO[]{};}
case "Sales": { return new BillingContactDTO[]{};}
}
return CRMContact[]{};
}
Sound off in the comments :-)
Upvotes: 0
Views: 301
Reputation: 2369
I would almost certainly create either different controllers or more likely, entirely separate projects
http://sales-hostname/api/contacts
http://billing-hostname/api/contacts
http://crm-hostname/api/contacts
If you try and combine into a single controller, using either method 1 or method 3 above, you're going to end up with it being responsible for too much. You'll end up with having to change it anytime any bounded context changes, not to mention any dependencies the controller will need.
Upvotes: 3