20 lines
695 B
C#
20 lines
695 B
C#
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
namespace NfProcessorApp.Handlers
|
|
{
|
|
public class FileHandlerFactory(IServiceProvider provider) : IFileHandlerFactory
|
|
{
|
|
private readonly IServiceProvider _provider = provider;
|
|
|
|
public IFileHandler CreateHandler(string filePath)
|
|
{
|
|
var ext = Path.GetExtension(filePath).ToLowerInvariant();
|
|
return ext switch
|
|
{
|
|
".xml" => _provider.GetRequiredService<XmlFileHandler>(),
|
|
".pdf" => _provider.GetRequiredService<PdfFileHandler>(),
|
|
_ => throw new NotSupportedException($"Extension not supported: {ext}")
|
|
};
|
|
}
|
|
}
|
|
} |