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-05-22 07:39:48 +03:00
|
|
|
|
"Excel" => (IWriter)_serviceProvider.GetService(typeof(ExcelWriter)),
|
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
|
|
|
|
}
|
|
|
|
|
}
|