Use of Dependency injection with ASP.NET services.
inject a QuarterlySalaryCalculator
class as ISalaryCalculator
using ASP.Net. The QuarterlySalaryCalculator
class should convert an annual salary into a quarterly salary.
- The files
Controllers/SalaryController.cs
,Services/MonthlySalaryCalculator.cs
,Services/ISalaryCalculator.cs
, andProgram.cs
remain unchanged in the solution. - A file
Services/QuarterlySalaryCalculator.cs
defines a class implementing theISalaryCalculator
interface. - The implementation of the
CalculateSalary
method in theQuarterlySalaryCalculator
class converts an annual salary into a quarterly salary. - In the
Program.cs
file, a call to theAddScoped
method injectsQuarterlySalaryCalculator
asISalaryCalculator
. - The route
Api/Salary/{annualAmount}
returns a quarterly salary.