-2

I'm building an API in .net that wil capture webhooks events of a third party service.

Lots of actions on the third party service will trigger the webhooks.

    account.deactivated",
    "account.deleted",
    "company.added",
    "company.deleted",
    "company.updated",
    "contact.added",
    "contact.deleted",
    "contact.linkedToCompany",
    "contact.unlinkedFromCompany",
    "contact.updated",
    "creditNote.booked",
    "deal.created",
    "deal.deleted",
    "deal.lost",
    "deal.moved",
    "deal.updated",
    "deal.won",
    "invoice.booked",
    "invoice.deleted",
    "invoice.drafted",
    "invoice.paymentRegistered",
    "invoice.paymentRemoved",
    "invoice.sent",
    "invoice.updated",
    "milestone.created",
    "milestone.updated",
    "product.added",
    "project.created",
    "project.deleted",
    "project.updated",
    "timeTracking.added",
    "timeTracking.deleted",
    "timeTracking.updated",
    "user.deactivated"

My question is should I capture this all in 1 Controller. This will reduce the amount of code. but certainly will make it lot more complex. Checking wich object it is making a dynamic insert/update to the database & ...

Or should't I create for every object a different controller, so know which object I have to handle.

0

The information you gave is a little sparse but from a very "far away"-point of view I would recommend using multiple controllers. In modern software engineering you should, as a rule of thumb, tend to reduce complexity wherever possible. This helps to fulfill non-functional requirements like:

  • Testability - you can mock data for every controller and every webhook separately
  • Maintainability - adding, bug fixing, removing functionality becomes easier per controller
  • etc.

Try to generalize common tasks between controllers. Otherwise it is no shame to introduce some redundant code.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.