/// <summary> /// Main program method that orchestrates all the individual services. /// </summary> /// <param name="serviceProvider"></param> /// <param name="runOptions"></param> static void Run(ServiceProvider serviceProvider, RunOptions runOptions) { var logger = serviceProvider?.GetService <ILogger>(); try { logger.Log(LogType.Trace, "Running monthly payslip program.."); //Create an employ with a salary logger.Log(LogType.Trace, "Creating an employee"); var employee = new Employee() { Name = runOptions.FullName, AnnualSalary = runOptions.GrossSalary }; // Create a Tax Processor factory logger.Log(LogType.Trace, "Creating a tax processing factory."); var taxProcessorFactory = new TaxProcessorFactory(serviceProvider); // Create a type of taxProcessor class var taxProcessor = taxProcessorFactory.CreateTaxProcessor(); if (taxProcessor == null) { logger.Log(LogType.Error, $"TaxProcessorFactory returned null from CreateTaxProcessor()."); return; } // Run the calculations to calculate monthly gross income, monthly income tax and , monthly net income. logger.Log(LogType.Trace, "Tax processor crunching calculations."); taxProcessor.RunCalculations(employee); //Display payslip. var textDisplayer = new TextDisplayer(serviceProvider); textDisplayer.DisplayPayslip(employee, taxProcessor); logger.Log(LogType.Trace, "finished running monthly payslip program.."); } catch (Exception e) { logger.Log(LogType.Error, $"Failed to run program exception: {e.Message}"); return; } }