diff --git a/Controllers/LendController.cs b/Controllers/LendController.cs index 6b90e16..40f02fc 100644 --- a/Controllers/LendController.cs +++ b/Controllers/LendController.cs @@ -13,13 +13,18 @@ namespace BuecherwurmAPI.Controllers [ApiController] public class LendController : ControllerBase { - private readonly MockLendRepo _mockLendRepo = new MockLendRepo(); + private ILendRepo _repository; + + public LendController(ILendRepo repository) + { + _repository = repository; + } //GET api/leihvorgang/ [HttpGet] public ActionResult> GetAllLends() { - var lends = _mockLendRepo.GetAllLends(); + var lends = _repository.GetAllLends(); return Ok(lends); } @@ -27,7 +32,7 @@ namespace BuecherwurmAPI.Controllers [HttpGet("{id}")] public ActionResult GetLend(int id) { - var lend = _mockLendRepo.GetLendById(id); + var lend = _repository.GetLendById(id); return Ok(lend); } } diff --git a/Startup.cs b/Startup.cs index 1bdfe77..4e77ad5 100644 --- a/Startup.cs +++ b/Startup.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; +using BuecherwurmAPI.Data; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.HttpsPolicy; @@ -26,6 +27,11 @@ namespace BuecherwurmAPI public void ConfigureServices(IServiceCollection services) { services.AddControllers(); + + // Adds a service that is created once per connection. + // It takes an interface and a specific implementation. + // That allows to swap the implementation easily. + services.AddScoped(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.