Configuring the background service

Now that we have defined the event bus abstraction, we can proceed by creating a new BackgroundService type that will use the IMediator interface to dispatch the sold-out messages. This book uses RabbitMQ because it is open source and easy to configure but keep in mind that there are tons of products and technologies related to this topic. Before continuing with the implementation of the background service, it is necessary to add some packages to the Cart.Infrastructure project:

dotnet add package RabbitMQ.Client

Furthermore, we can proceed by creating a new class that extends the BackgroundService type:

using System;using System.Threading;using System.Threading.Tasks;using Cart.Domain.Events;using Cart.Infrastructure.Configurations; ...

Get Hands-On RESTful Web Services with ASP.NET Core 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.