DavidAJohn / PhotoPortfolio

Personal photo portfolio .NET web application which implements a Blazor and Tailwind CSS user interface with a MongoDb database, and includes integration with Stripe Checkout and Prodigi Print API
0 stars 0 forks source link

Messaging should be generic #62

Closed DavidAJohn closed 9 months ago

DavidAJohn commented 9 months ago

Although there's only one type of message being sent to the Azure Service Bus queue at the moment, the sender and consumer classes should be generic, so that they can be used for other types of message in the future.

I've been doing this long enough now to know that no matter how unlikely you think it is that you'll need a set of classes in some other context, it's always a possibility, particularly once you know that it's now an option. So make it generic if you can.

Ideally, I would add the message type as metadata in the message. I believe the ServiceBusMessage class has a property called ApplicationProperties that can store a Dictionary, so in this case it would contain something like: { "MessageType" : "OrderApproved" }.

The consumer class can then deserialize the body content to the type specified.