pikachumm / CalculatorService

0 stars 0 forks source link

Separate concerns in CalculatorController.cs #9

Open atthepit opened 4 years ago

atthepit commented 4 years ago

Following what I said in #6 try to separate the code present in CalculatorController in smaller classes that are responsible only for one thing.

https://github.com/pikachumm/CalculatorService/blob/21d5ad8f28f037db010e9aae5dcb3347b3757dba/CalculadoraServer/Controllers/CalculatorController.cs#L38-L53

For example, in the code above you have two clear responsibilities, perform the sum and store the operation in a journal. I would create a couple new classes.

The controller would then be responsible only to read the request, call this classes if needed, and build and return the response.

You can also use this to learn about Inversion of control / Dependency Injection and how we use it at Evicertia: https://www.martinfowler.com/bliki/InversionOfControl.html https://aspnetboilerplate.com/Pages/Documents/Dependency-Injection