From the course: .NET Microservices for Azure Developers

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Solution: Implementing BreedsController and validations

Solution: Implementing BreedsController and validations - Azure Tutorial

From the course: .NET Microservices for Azure Developers

Solution: Implementing BreedsController and validations

(upbeat music) - [Instructor] Let me show you how I managed to implement the BreedsController class and how I implemented the logger object. So here's the class. You can see that I'm injecting both ManagementDbContext and the ILogger of BreedsController objects. And here I'm validating if there's nothing in the database, I'm returning 404, and in this other method as well. This method is named GetBreedById, and I'm actually using that as the route name since the route name should be different than the one that we have in the PetsController class. And here you can see that I implemented this try-catch block, since this is the place where I'm using the logger object and returning 500. Down below, you can find the new breed record and I'm using zero as a value for the ID since the entity framework core is going to set the correct ID after the new item is inserted in the database. So let's open up PetsController so you can see that I'm also injecting ILogger of PetsController, validating…

Contents