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

21 lines
754 B
C#
Raw Permalink Normal View History

2023-11-09 23:34:52 +03:00
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}")
};
}
}