SHA256
Initial implementation for address search/query using external APIs (OSM Nominatim) & Added required classes for supporting more APIs in the future.
28 lines
1014 B
C#
28 lines
1014 B
C#
using Microsoft.Extensions.Options;
|
|
using Somnia.GuestLog.Models.Configuration;
|
|
using Somnia.GuestLog.Utils.DI;
|
|
|
|
namespace Somnia.GuestLog.Services.AddressQuery;
|
|
|
|
public class ConfigFileAddressQueryFactory(
|
|
IServiceProvider serviceProvider,
|
|
IOptions<AddressQueryConfig> config
|
|
) : IAddressQueryFactory, IFactoryDI
|
|
{
|
|
public static void RegisterFactoryItems(IServiceCollection services)
|
|
{
|
|
services.AddKeyedTransient<IAddressQueryService, NominatimAddressQueryService>(AddressQueryConfig.AddressQueryProviderEnum.Nominatim);
|
|
}
|
|
|
|
public IAddressQueryService GetService()
|
|
{
|
|
if (config.Value.EnableAddressQuery == false)
|
|
{
|
|
throw new InvalidOperationException("AddressQuery is disabled. Enable and configure it first!");
|
|
}
|
|
|
|
return serviceProvider.GetKeyedService<IAddressQueryService>(config.Value.Provider)
|
|
?? throw new InvalidOperationException($"AddressQueryService not found for provider: '{config.Value.Provider}'");
|
|
}
|
|
}
|