2023-04-17 08:49:26 +03:00
|
|
|
|
namespace RhSolutions.Services;
|
|
|
|
|
|
|
|
|
|
public class WriterFactory
|
|
|
|
|
{
|
|
|
|
|
private readonly IServiceProvider _serviceProvider;
|
|
|
|
|
|
|
|
|
|
public WriterFactory(IServiceProvider serviceProvider)
|
|
|
|
|
{
|
|
|
|
|
_serviceProvider = serviceProvider;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-20 09:37:07 +03:00
|
|
|
|
public IWriter GetWriter(string writerName)
|
2023-04-17 08:49:26 +03:00
|
|
|
|
{
|
2023-05-22 07:31:53 +03:00
|
|
|
|
return writerName switch
|
2023-04-17 08:49:26 +03:00
|
|
|
|
{
|
2023-06-20 07:25:44 +03:00
|
|
|
|
"NewPrice" => (IWriter)_serviceProvider.GetService(typeof(NewPriceWriter)),
|
2023-05-22 07:31:53 +03:00
|
|
|
|
"Dxf" => (IWriter)_serviceProvider.GetService(typeof(DxfWriter)),
|
2023-05-30 08:23:31 +03:00
|
|
|
|
_ => throw new ArgumentException($"Незвестный интерфейс {nameof(IWriter)}: {writerName}")
|
2023-05-22 07:31:53 +03:00
|
|
|
|
};
|
2023-04-17 08:49:26 +03:00
|
|
|
|
}
|
2023-06-20 08:14:01 +03:00
|
|
|
|
}
|