Questions
Answer the following questions to test the knowledge that you have gained in this chapter:
- We have a class that we want to register for dependency injection. During the handling of a request, the class will be referenced several times by other classes. We want a new instance of the class to be created when injected into a class rather than an existing instance to be used. 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) { Â Â ...