Add dependency Injection
This commit is contained in:
@@ -8,11 +8,11 @@ namespace GerbilManager.Controllers
|
||||
[Route("gerbils")]
|
||||
public class GerbilsController : ControllerBase
|
||||
{
|
||||
private readonly InMemGerbilRepository repository;
|
||||
private readonly IGerbilRepository repository;
|
||||
|
||||
public GerbilsController()
|
||||
public GerbilsController(IGerbilRepository repo)
|
||||
{
|
||||
repository = new InMemGerbilRepository();
|
||||
this.repository = repo;
|
||||
}
|
||||
|
||||
//GET /gerbils
|
||||
@@ -22,5 +22,18 @@ namespace GerbilManager.Controllers
|
||||
var items = repository.GetGerbils();
|
||||
return items;
|
||||
}
|
||||
|
||||
//GET /gerbils
|
||||
[HttpGet("{id}")]
|
||||
public ActionResult<Gerbil> GetGerbil(Guid id)
|
||||
{
|
||||
var item = repository.GetGerbil(id);
|
||||
|
||||
if(item is null)
|
||||
{
|
||||
return NotFound();
|
||||
}
|
||||
return item;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user