December 2019
Intermediate to advanced
510 pages
11h 33m
English
We have just seen how we can initialize services in our Startup class, but how can we consume these services? By default, the built-in dependency injection container of ASP.NET Core uses the constructor injection pattern to retrieve services. We can modify ValueController to use IPaymentServices by adding the interface as a parameter of the controller constructor:
using Microsoft.AspNetCore.Mvc;namespace SampleAPI.Controllers{ [ApiController] [Route("[controller]")] public class ValuesController : ControllerBase { private IPaymentService paymentService { get; set; } public ValuesController(IPaymentService paymentService) { this.paymentService = paymentService; } public string Get() { return paymentService.GetMessage ...
Read now
Unlock full access