Add dependency Injection

This commit is contained in:
2023-10-16 22:02:02 +02:00
parent 3e3ef39b80
commit 707bfae2e3
4 changed files with 33 additions and 6 deletions

View File

@@ -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;
}
}
}