RhSolutions-AddIn/RhSolutions.AddIn/Services/FittingsCalculatorFactory.cs

21 lines
754 B
C#

namespace RhSolutions.Services;
public class FittingsCalculatorFactory
{
private readonly IServiceProvider _serviceProvider;
public FittingsCalculatorFactory(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}
public IFittingsCalculator GetFittingsCalculator(string calculatorName)
{
return calculatorName switch
{
"Sleeves" => (IFittingsCalculator)_serviceProvider.GetService(typeof(SleevesCalculator)),
"Couplings" => (IFittingsCalculator)_serviceProvider.GetService(typeof(CouplingsCalculator)),
_ => throw new ArgumentException($"Незвестный интерфейс {nameof(IFittingsCalculator)}: {calculatorName}")
};
}
}