SHA256
feat StayExport - Refactor Export Services.
- Created new service: IStayExportService" for common export operations. - Updated older services to be "IStayExportFormatProvider". This services will only implement the export format. - Renamed "IStayExportServiceFactory" to "IStayExportFormatProviderFactory" as this factory now is used to get the format providers for the given format.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using Microsoft.Extensions.Options;
|
||||
using Somnia.GuestLog.Enums.Models;
|
||||
using Somnia.GuestLog.Models.Configuration;
|
||||
using Somnia.GuestLog.Utils.DI;
|
||||
|
||||
namespace Somnia.GuestLog.Services.StayExport;
|
||||
|
||||
public class StayExportFormatProviderFactory(
|
||||
IServiceProvider serviceProvider,
|
||||
IOptions<StayExportConfig> config
|
||||
) : IStayExportFormatProviderFactory, IFactoryDI
|
||||
{
|
||||
public static void RegisterFactoryItems(IServiceCollection services)
|
||||
{
|
||||
services.AddKeyedSingleton<IStayExportFormatProvider, StayExportProviderJson>(StayExportFormat.GuestLogJson);
|
||||
services.AddKeyedSingleton<IStayExportFormatProvider, StayExportProviderSpainParteViajeros>(StayExportFormat.SpainParteViajeros);
|
||||
}
|
||||
|
||||
|
||||
public IStayExportFormatProvider GetProvider(StayExportFormat exportFormat)
|
||||
{
|
||||
if (config.Value.EnableStayExport == false)
|
||||
{
|
||||
throw new InvalidOperationException("StayExport is disabled. Enable and configure it first!");
|
||||
}
|
||||
|
||||
return serviceProvider.GetKeyedService<IStayExportFormatProvider>(exportFormat)
|
||||
?? throw new InvalidOperationException($"StayExport service not found for ExportFormat: '{exportFormat}'");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user