Last active
January 22, 2021 15:59
-
-
Save nosavvy33/ff41f0e610cc2c8095a236dcd5c9bb75 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // in Services\Calculator\CalculatorService.cs | |
| public class CalculatorService : ICalculator | |
| { | |
| // this was added | |
| private readonly IPrinter _printer; | |
| public CalculatorService( IPrinter printer) | |
| { | |
| this._printer = printer; | |
| } | |
| public int Substract(int a, int b) | |
| { | |
| return a - b; | |
| } | |
| public int Sum(int a, int b) | |
| { | |
| // every time we sum, a ping pong is printed | |
| this._printer.PingPong(); | |
| return a + b; | |
| } | |
| } | |
| // in Controllers\CalculatorController.cs | |
| [ApiController] | |
| [Route("calculator")] | |
| public class CalculatorController : Controller | |
| { | |
| //this was added | |
| private readonly IPrinter _printer; | |
| private readonly ICalculator _calculator; | |
| public CalculatorController(IPrinter printer, ICalculator calculator) | |
| { | |
| // this was added | |
| this._printer = printer; | |
| this._calculator = calculator; | |
| } | |
| [HttpGet("sum")] | |
| public IActionResult Sum([FromQuery] int a, [FromQuery] int b) | |
| { | |
| // this was added | |
| this._printer.PingPong(); | |
| // printing the result is not needed, just to print it from the CalculatorService | |
| this._calculator.Sum(a, b); | |
| return Ok(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment