From the course: Advanced Azure Microservices with .NET for Developers

Handling the domain event and creating the integration event - Azure Tutorial

From the course: Advanced Azure Microservices with .NET for Developers

Handling the domain event and creating the integration event

- In this video, we'll handle all the main event. This event it's triggered when a user flags a pet for adoption. We're going to handle the event in the pet application service class of the Pet Domain Project. Okay. Let's fire up visual studio and let's open the solution. Here we are in visual studio and let me show you the event that we're going to handle that is right here inside the Pet Domain Project Events right here, pets flagged for adoption. This is the Event, as you can see, it's a class that implements IDomain Event and it has different properties that we're going to send over to other microservices that are interested in this data. Okay, we're going to handle this Event inside the Pet Application Service Class that is inside the Pet API Project. So right here in the constructor, I'm going to type Domain Events, which is a study class that is inside the Pet Domain Project as well. And I'm going to use this field that has this Register method. It allows me to pass this action of Pet Flagged for Adoption. I'm going to pass just a Lambda Expression right here. So as you can see, I'm receiving Pet Flagged for Adoption, which is the Event that I'm receiving. But actually we don't want to use Pet Flagged for Adoption outside this microservice because we don't want to leak the domain model, instead we're need another class. So let's create a new Folder here (typing) named Integration Events and I'm going to create a new class named Pet Flagged for Adoption Integration Event. And this class is going to implement I Integration Event. That is a marker interface that we have in the common project. It's just a marker interface. It doesn't have any functionality. And here we're going to implement the same properties as Pet Flagged for Adoption. So let's copy this and paste them right here. So we're ready to create a new Integration Event when we receive the Domain Event. So I don't want you to see me typing because of that I'm going to paste the code that I already created and let me just solve this name space. Perfect. So as you can see, we're creating these new object of type Pet Flagged for Adoption Integration Event based on the same data that we're receiving from the event. So we can test this by following the flow of execution. So I'm going to insert this Break Point right here and let's start Debugging. The first thing that we need to do in order to test this Flagged for Adoption Event is to create a pet. So I'm going to click on this end point and I'm going to click on Try It Out and let's create a new pet. (typing) Jani, beagle, white, brown and black, let's say 2011, and this is a dog. Okay, let's execute this. I received 200. And so we're ready to test the Flag for Adoption. So let's cancel this and let's scroll down a little bit so we can find this Flag for Adoption and let's click on Post, try it out and Execute. As you can see I inserted another breakpoint in the controller. Let's click on F5 And finally we receive the Event inside the code that we just created. We're receiving the data from this pet that we're marking or flagging for adoption. Okay, excellent. Follow me in the next video because we're going to send this integration event to Azure Service Bus.

Contents