Answer the following questions to test the knowledge we have gained in this chapter:
- We have a class that we want to register for dependency injection and want a new instance of it to be created when injected into a class. What method in IServiceCollection should we use to register the dependency?
- In a controller action method, if a resource can't be found, what method can we use in ControllerBase to return status code 404?
- In a controller action method to post a new building, we implement some validation that requires a database call to check whether the building already exists. If the building does already exist, we want to return HTTP status code 400:
[HttpPost]
public ActionResult<BuildingResponse> PostBuilding(BuildingPostRequest buildingPostRequest)
{
var buildingExists =
_dataRepository.BuildingExists(buildingPostRequest.Code);
if (buildingExists...