Implementing a delegation

This project is part of the MessageHandler processing patterns library.

MessageHandler is distributed under a commercial license, for more information on the terms and conditions refer to our license page.

What is a delegation

A delegation responds to a command by invoking another command.

Reaction

When to use it

Use this pattern every time something needs to happen in another location.

Scenario

The scenario for this quickstart is a command to notify an e-commerce buyer through email, but it is delegated from an API to a Worker and in turn again to a specialized email service.

What you need to get started

Running the sample

Prior to being able to run the sample, you need to configure the user secrets file.

In the secrets file you must specify the following configuration values.

{
  "servicebusnamespace": "your azure service bus connection string goes here"
}

Also ensure a queue named emails is created up front in the service bus namespace.

Once configured you can start the worker or run the unittests.

Designed with testing in mind

MessageHandler is intented to be test friendly.

This sample contains plenty of ideas on how to test a delegation without requiring a dependency on an actual broker instance, and thus keep the tests fast.

  • Component tests: To test the delegation logic and it's interaction with the email service.
  • Contract tests: To verify that the test doubles used in the component tests are behaving the same as an actual dependency would. Note: contract verification files are often shared between producers and consumers of the contract.

How to implement it yourself

Check out this how to guide to learn how to configure a delegation yourself.